Last active
November 18, 2017 21:10
-
-
Save travisbrown/06a80937caf5d29df9f7ae2c12e5184a 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
// Before | |
import io.circe.Decoder | |
case class Qux(a: Int, b: String) | |
val decodeQuxMonadic: Decoder[Qux] = Decoder.instance { c => | |
for { | |
a <- c.get[Int]("a") | |
b <- c.get[String]("b") | |
} yield Qux(a, b) | |
} | |
// After | |
import cats.implicits._ | |
import io.circe.Decoder | |
case class Qux(a: Int, b: String) | |
val decodeQuxApplicative: Decoder[Qux] = ( | |
Decoder[Int].prepare(_.downField("a")), | |
Decoder[String].prepare(_.downField("b")) | |
).mapN(Qux.apply _) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment