scala - Transform and flatten List of disjunctions -
scala - Transform and flatten List of disjunctions -
case class errs(errors: list[err]) case class err(exceptionmessage: string, custommessage: string, statuscode: int, extrainfo: option[string] = none)
one of functions returning val result = list[\/[errs, boolean]]
in order transform/sequence , flatten result next passes done
val finalres: \/[errs, boolean] = result.map(_.swap).sequenceu.map(x => errs(x.map(_.errors).flatten)).swap
this looks inelegant , performance intensive (given number of passes has via multiple map calls etc)
is there combinator in scalaz can create more elegant less number of passes or demands writing custom function?
firstly, utilize traverseu, suggested travis brown.
after that, phone call map followed phone call flatten can written flatmap.
val finalres: \/[errs, boolean] = result.traverseu(_.swap).map(x => errs(x.flatmap(_.errors))).swap moreover, may consider using type alias errs.
type errs = list[err] so, code simpler (less boxing/unboxing) :
val finalres: \/[errs, boolean] = result.traverseu(_.swap).map(_.flatten).swap scala scalaz
Comments
Post a Comment