The example from the documentation fails on Scala 2.11.11, but I can run it successfully on Scala 2.12.x
scala> class Thing(val foo: String, val bar: Int)
defined class Thing
scala> implicit val encodeFoo: Encoder[Thing] = new Encoder[Thing] {
| final def apply(a: Thing): Json = Json.obj(
| ("foo", Json.fromString(a.foo)),
| ("bar", Json.fromInt(a.bar))
| )
| }
encodeFoo: io.circe.Encoder[Thing] = $anon$1@bfe134d
scala> implicit val decodeFoo: Decoder[Thing] = new Decoder[Thing] {
| final def apply(c: HCursor): Decoder.Result[Thing] =
| for {
| foo <- c.downField("foo").as[String]
| bar <- c.downField("bar").as[Int]
| } yield {
| new Thing(foo, bar)
| }
| }
<console>:17: error: value flatMap is not a member of io.circe.Decoder.Result[String]
foo <- c.downField("foo").as[String]
^
<console>:18: error: value map is not a member of io.circe.Decoder.Result[Int]
bar <- c.downField("bar").as[Int]
got the same error on scala 2.10.6
I have the same issue on Scala 2.11, with Circe 0.5.2 version
I think the problem is that the Scala 2.11.x Either does not have the map/flatMap, the new methods are introduced in the 2.12 version
To overcome this issue you can use cats either, simply import it:
import cats.syntax.either._
Why not update this in the document? new users may get stuck in this problem.
@djvulee This has slipped through the cracks, but a PR would be very welcome.
Most helpful comment
To overcome this issue you can use cats either, simply import it:
import cats.syntax.either._