Skip to content

Instantly share code, notes, and snippets.

@joshcough
Created September 18, 2015 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshcough/64124148a58706b0ec36 to your computer and use it in GitHub Desktop.
Save joshcough/64124148a58706b0ec36 to your computer and use it in GitHub Desktop.
implicit class RichV[S[_]:Applicative,E,T](v:Validation[E, T])
(implicit sg: Semigroup[S[E]]){
def leftFlatMap[U](f: E => Validation[S[E],U]): Validation[S[E],T] =
v.leftMap{ e => f(e).fold(sg.append(e.point[S], _), _ => e.point[S]) }
}
implicit class RichNelV[S[_],E,T](v:Validation[S[E], T])
(implicit sg: Semigroup[S[E]]){
def leftFlatMap[U](f: S[E] => Validation[S[E],U]): Validation[S[E],T] =
v.leftMap{ es => f(es).fold(sg.append(_, es), _ => es) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment