Skip to content

Instantly share code, notes, and snippets.

@mdedetrich
Created March 27, 2018 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdedetrich/fa48b01febbbbade6b260bf9258535a1 to your computer and use it in GitHub Desktop.
Save mdedetrich/fa48b01febbbbade6b260bf9258535a1 to your computer and use it in GitHub Desktop.
If macros example
```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