1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00

Parametric JSON conversion for Patch.

This commit is contained in:
Rob Rix 2015-10-08 07:28:03 -04:00
parent d8e8d4d91f
commit 5610b9737c

View File

@ -84,6 +84,32 @@ extension Patch {
}
// MARK: - JSONConvertible
extension Patch {
public func JSON(ifLeaf: A -> Doubt.JSON) -> Doubt.JSON {
switch self {
case let .Replace(a, b):
return Doubt.JSON.Dictionary([
"case": .String("Replace"),
"before": a.JSON(ifLeaf),
"after": b.JSON(ifLeaf),
])
case let .Insert(b):
return Doubt.JSON.Dictionary([
"case": .String("Insert"),
"after": b.JSON(ifLeaf),
])
case let .Delete(a):
return Doubt.JSON.Dictionary([
"case": .String("Delete"),
"before": a.JSON(ifLeaf)
])
}
}
}
/// A hack to enable constrained extensions on `Free<A, Patch<A>>`.
public protocol PatchConvertible {
typealias Info