From 01d65a4245a34ddd1b650888e655882a33efb271 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 16 Oct 2015 11:09:30 -0400 Subject: [PATCH] Patches of terms annotated with ranges can produce JSON over source strings. --- prototype/Doubt/Patch.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/prototype/Doubt/Patch.swift b/prototype/Doubt/Patch.swift index 0c242e2ec..bece84799 100644 --- a/prototype/Doubt/Patch.swift +++ b/prototype/Doubt/Patch.swift @@ -140,3 +140,13 @@ extension Patch: PatchType { self = .Insert(after) } } + + +extension PatchType where Element: CofreeType, Element.Annotation == Range { + public func JSON(a a: String, b: String) -> Doubt.JSON { + return [ + "before": state.before.map { $0.JSON(a) } ?? nil, + "after": state.after.map { $0.JSON(b) } ?? nil, + ] + } +}