The following is an example of toys to demonstrate the strange shape and meaning of the question about real life methods.
As you can see anotherFunc , after displaying over personList , the type expands to \/[Throwable,List[\/[Throwable,String]]] , which is not intended for the return type, but the effect is map ing personList . again, what is shown below inside anotherFunc is for demo purpose (actually, more meaningful things happen instead of Option("fakeString") or any of them.
The requirement is a map personList , and if it is right , then do something with each List[Person] element returned from right (the side that was returned from the disjunction).
how to simplify / smooth the return type of anotherFunc (return \/[Throwable,List[String]] ). Can other combinators be used?
case class Person(name :String) def personList : \/[Throwable,List[Person]] ={ \/.fromTryCatch{ List(Person("John")) } } def anotherFunc : \/[Throwable,List[\/[Throwable,String]]]= { personList.map{ pl => pl.map{p => for{ s <- Option("fakeString").\/>(new Throwable("not found")) } yield s } } }
source share