1
1
mirror of https://github.com/github/semantic.git synced 2025-01-01 11:46:14 +03:00

Parametric JSON conversion for Free.

This commit is contained in:
Rob Rix 2015-10-08 07:21:08 -04:00
parent 44d2804367
commit 22b77ecd76

View File

@ -163,3 +163,12 @@ extension Free where A: Hashable, B: Hashable {
return hash(ifPure: Hash.init, ifRoll: Hash.init)
}
}
// MARK: - JSONConvertible
extension Free {
public func JSON(ifPure ifPure: B -> Doubt.JSON, ifLeaf: A -> Doubt.JSON) -> Doubt.JSON {
return analysis(ifPure: ifPure, ifRoll: { $0.JSON(ifLeaf: ifLeaf, ifRecur: { $0.JSON(ifPure: ifPure, ifLeaf: ifLeaf) }) })
}
}