Created
March 27, 2018 22:50
-
-
Save mdedetrich/fa48b01febbbbade6b260bf9258535a1 to your computer and use it in GitHub Desktop.
If macros example
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
```scala | |
implicit def decoder | |
#IF-SCALA < 2.13 | |
[C[A] <: Traversable[A]](implicit cbf: MyCollection.CBF1[C],cbf2: MyCollection.CBF2[C]): Decoder[MyCollection[C]] | |
#ELSE | |
[C[A] <: Traversable[A]](implicit builder: Builder[C]): Decoder[MyCollection[C]] | |
#DONE | |
= new Decoder[MyCollection[C]] { | |
override def apply(c: HCursor): Decoder.Result[MyCollection[C]] = { | |
( | |
c.downField("stuff").as[Option[C[Wrapper]]] |@| | |
c.downField("recursive_stuff").as[Option[C[MyCollection[C]]]] | |
).map(MyCollection.apply) | |
} | |
} | |
def getMyCollection2 | |
#IF-SCALA < 2.13 | |
[C[A] <: Traversable[A]](implicit cbf: MyCollection.CBF1[C], | |
cbf2: MyCollection.CBF2[C]): MyCollection[C] | |
#ELSE | |
[C[A] <: Traversable[A]](implicit builder: Builder[C]): MyCollection[C] | |
#DONE | |
= { | |
val jsonString = """ | |
{ | |
"stuff": ["a", "b"], | |
"recursive_stuff": [{ | |
"stuff": ["c"] | |
}] | |
} | |
""" | |
val json = io.circe.parser.parse(jsonString).right.get | |
json.as[MyCollection[C]].right.get | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment