diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index 52b34c0a0..ec8c23eac 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -94,4 +94,16 @@ extension Cofree where A: Hashable, B: Hashable { } +// MARK: - JSON + +extension Cofree { + public func JSON(annotation annotation: B -> Doubt.JSON, leaf: A -> Doubt.JSON) -> Doubt.JSON { + return [ + "extract": annotation(extract), + "unwrap": unwrap.JSON(ifLeaf: leaf, ifRecur: { $0.JSON(annotation: annotation, leaf: leaf) }) + ] + } +} + + import Prelude