From 8f86f9ab7664ce655bde73fa27ba56ac16769669 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 14 Oct 2015 10:59:41 -0400 Subject: [PATCH] Parameterized JSON conversion for Cofree. --- prototype/Doubt/Cofree.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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