-
-
Save stephen-lazaro/2897c5e1413685b309d74e3658e16dec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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