Skip to content

Instantly share code, notes, and snippets.

@stephen-lazaro
Last active November 9, 2018 18:50
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 stephen-lazaro/2897c5e1413685b309d74e3658e16dec to your computer and use it in GitHub Desktop.
Save stephen-lazaro/2897c5e1413685b309d74e3658e16dec to your computer and use it in GitHub Desktop.
implicit val monoidalForRowDecoder = new Monoidal[RowDecoder] {
 // This always succeeds returning the given value!
 def pure[A](x: A): RowDecoder[A] =
  RowDecoder.from(Function.const(Right(x)))
// This processes the output of the given decode with the given function
  def map[A, B](fa: RowDecoder[A])(f: A => B): RowDecoder[B] =
  RowDecoder.from(x => fa.decode(x).map(f))
// Combine the output of two into one!
def product[A, B](fa: RowDecoder[A], fb: RowDecoder[B]): RowDecoder[(A, B)] =
  RowDecoder.from(x => fa.decode(x).flatMap(a => f.decode(x).map(b => (a, b))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment