1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 17:59:10 +03:00

Free is CustomDocConvertible.

This commit is contained in:
Rob Rix 2015-10-07 09:50:31 -04:00
parent 804e831705
commit 2a8e017282

View File

@ -5,7 +5,7 @@
/// `Syntax` is a non-recursive type parameterized by the type of its child nodes. Instantiating it to `Free` makes it recursive through the `Roll` case, and allows it to wrap values of type `B` through the `Pure` case.
///
/// In Doubt, this allows us to represent diffs as values of the `Free` monad obtained from `Syntax`, injecting `Patch` into the tree; or otherwise put, a diff is a tree of mutually-recursive `Free.Roll`/`Syntax` nodes with `Pure` nodes injecting the actual changes.
public enum Free<A, B>: CustomDebugStringConvertible {
public enum Free<A, B>: CustomDebugStringConvertible, CustomDocConvertible {
/// The injection of a value of type `B` into the `Syntax` tree.
case Pure(B)
@ -85,6 +85,18 @@ public enum Free<A, B>: CustomDebugStringConvertible {
return ".Roll(\(String(reflecting: s)))"
}
}
// MARK: CustomDocConvertible
public var doc: Doc {
switch self {
case let .Pure(b):
return Doc(b)
case let .Roll(s):
return s.doc
}
}
}