Created
March 14, 2019 20:42
-
-
Save qingwei91/1f3453eb6e022255290326fb96260dbd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import $ivy.`io.circe::circe-parser:0.10.0` | |
| import io.circe.Decoder | |
| val toDecoder: HAlgebra[QueryF, Decoder] = new HAlgebra[QueryF, Decoder] { | |
| override def apply[A](fa: QueryF[Decoder, A]): Decoder[A] = fa match { | |
| case QueryBoolF => Decoder.decodeBoolean | |
| case QueryStringF => Decoder.decodeString | |
| case q: QueryPathF[Decoder, A] => | |
| Decoder.instance { cursor => | |
| cursor.get(q.path)(q.next) | |
| } | |
| } | |
| } | |
| val decoder = hCata(toDecoder, nestedQuery) | |
| val json = parse(""" | |
| { | |
| "oh": { | |
| "my": "20202" | |
| } | |
| } | |
| """).right.get | |
| decoder.decode(json) // Right("20202") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment