Created
January 8, 2014 18:29
-
-
Save tpolecat/8321821 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
implicit def treeEncode[A: EncodeJson]: EncodeJson[Tree[A]] = | |
EncodeJson(t => (t.rootLabel, t.subForest).asJson) | |
implicit def treeDecode[A: DecodeJson]: DecodeJson[Tree[A]] = | |
DecodeJson(c => | |
for { | |
rootLabel <- (c =\ 0).as[A] | |
subForest <- (c =\ 1).as[Stream[Tree[A]]] | |
} yield Tree.node(rootLabel, subForest) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was wondering how this would work; I guess
treeEncode
can be applied tot.subForest
again?