mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Switch in Free.JSON
directly.
This commit is contained in:
parent
4f16ce62c3
commit
db7c1dc1ef
@ -217,14 +217,17 @@ public func == <Term: CofreeType, Annotation where Term.Leaf: Equatable> (left:
|
||||
|
||||
extension Free {
|
||||
public func JSON(pure pure: Value -> Doubt.JSON, leaf: Leaf -> Doubt.JSON, annotation: Annotation -> Doubt.JSON) -> Doubt.JSON {
|
||||
return analysis(
|
||||
ifPure: { [ "pure": pure($0) ] },
|
||||
ifRoll: {
|
||||
[ "roll": [
|
||||
"extract": annotation($0),
|
||||
"unwrap": $1.JSON(leaf: leaf, recur: { $0.JSON(pure: pure, leaf: leaf, annotation: annotation) })
|
||||
] ]
|
||||
})
|
||||
switch self {
|
||||
case let .Pure(a):
|
||||
return [ "pure": pure(a) ]
|
||||
case let .Roll(a, b):
|
||||
return [
|
||||
"roll": [
|
||||
"extract": annotation(a),
|
||||
"unwrap": b.JSON(leaf: leaf, recur: { $0.JSON(pure: pure, leaf: leaf, annotation: annotation) })
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user