-
-
Save stephen-lazaro/15aff2965d61346c4646af03771deb24 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 alternativeForRowDecoder = | |
new Alternative[RowDecoder] { | |
// Kind of like true, same as in our Monoidal above | |
def pure[A](x: A): RowDecoder[A] = | |
Monoidal[RowDecoder].pure(x) | |
// Kind of like AND, same as in our Monoidal abaove | |
def product[A, B](fa: RowDecoder[A], fb: RowDecoder[B]): RowDecoder[(A, B)] = | |
Monoidal[RowDecoder].product(fa, fb) | |
// Kind of like false but for decoders | |
def empty[A]: F[A] = | |
new RowDecoder[A] { | |
def apply(s: String) = Left(new RuntimeError("no dice")) | |
} | |
// Kind of like XOR but for decoders | |
def combineK[A](x: F[A], y: F[A]): F[A] = | |
RowDecoder.from(z => | |
x.decode(z) match { | |
case Left(_) => y.decode(z) | |
case Right(v) => Right(v) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment