1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +03:00

Evaluation of FreeAlgorithm.

This commit is contained in:
Rob Rix 2015-10-05 12:32:21 -04:00
parent fa3be5108e
commit 346a39fafc

View File

@ -77,4 +77,14 @@ public enum FreeAlgorithm<A, B> {
public func flatMap<C>(transform: B -> FreeAlgorithm<A, C>) -> FreeAlgorithm<A, C> {
return analysis(ifPure: transform, ifRoll: { .Roll($0.map { $0.flatMap(transform) }) })
}
public func evaluate(equals: (A, A) -> Bool) -> B {
switch self {
case let .Pure(b):
return b
case let .Roll(r):
return r.evaluate(equals).evaluate(equals)
}
}
}