1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Rename TermType.out to TermType.unwrap.

This commit is contained in:
Rob Rix 2015-10-15 09:18:55 -04:00
parent cb5dde7bb1
commit 59947a6581
3 changed files with 7 additions and 11 deletions

View File

@ -62,7 +62,7 @@ public enum Algorithm<Term: TermType, B> {
// At the moment, there are no restrictions on whether terms are compatible.
if equals(a, b) { return f(Diff(b)).evaluate(equals, recur: recur) }
switch (a.out, b.out) {
switch (a.unwrap, b.unwrap) {
case let (.Indexed(a), .Indexed(b)) where a.count == b.count:
return f(.Indexed(zip(a, b).map(recurOrReplace))).evaluate(equals, recur: recur)
@ -96,7 +96,7 @@ extension Algorithm where Term: Equatable {
extension Algorithm where B: FreeConvertible, B.RollType == Term.LeafType, B.PureType == Algorithm<Term, B>.Patch {
/// `Algorithm<Term, Diff>`s can be constructed from a pair of `Term`s using `ByKey` when `Keyed`, `ByIndex` when `Indexed`, and `Recursive` otherwise.
public init(_ a: Term, _ b: Term) {
switch (a.out, b.out) {
switch (a.unwrap, b.unwrap) {
case let (.Keyed(a), .Keyed(b)):
self = .Roll(.ByKey(a, b, Syntax.Keyed >>> Free.Roll >>> B.init >>> Pure))
case let (.Indexed(a), .Indexed(b)):

View File

@ -13,9 +13,9 @@ public enum Free<A, B>: CustomDebugStringConvertible, SyntaxConvertible {
indirect case Roll(Syntax<Free, A>)
/// Recursively copies a `Term: TermType where Term.LeafType == A` into a `Free<A, B>`, essentially mapping `Term.out` onto `Free.Roll`.
/// Recursively copies a `Term: TermType where Term.LeafType == A` into a `Free<A, B>`, essentially mapping `Term.unwrap` onto `Free.Roll`.
public init<Term: TermType where Term.LeafType == A>(_ term: Term) {
self = .Roll(term.out.map(Free.init))
self = .Roll(term.unwrap.map(Free.init))
}

View File

@ -2,21 +2,17 @@
public protocol TermType {
typealias LeafType
var out: Syntax<Self, LeafType> { get }
var unwrap: Syntax<Self, LeafType> { get }
}
extension Cofree: TermType {
public var out: Syntax<Cofree, A> {
return unwrap
}
}
extension Cofree: TermType {}
// MARK: - Equality
extension TermType {
public static func equals(leaf: (LeafType, LeafType) -> Bool)(_ a: Self, _ b: Self) -> Bool {
return Syntax.equals(ifLeaf: leaf, ifRecur: equals(leaf))(a.out, b.out)
return Syntax.equals(ifLeaf: leaf, ifRecur: equals(leaf))(a.unwrap, b.unwrap)
}
}