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

FreeAlgorithm is a monad.

This commit is contained in:
Rob Rix 2015-10-05 12:30:10 -04:00
parent c70ab9e9a4
commit fa3be5108e

View File

@ -73,4 +73,8 @@ public enum FreeAlgorithm<A, B> {
public func map<Other>(transform: B -> Other) -> FreeAlgorithm<A, Other> {
return analysis(ifPure: transform >>> FreeAlgorithm<A, Other>.Pure, ifRoll: { .Roll($0.map { $0.map(transform) }) })
}
public func flatMap<C>(transform: B -> FreeAlgorithm<A, C>) -> FreeAlgorithm<A, C> {
return analysis(ifPure: transform, ifRoll: { .Roll($0.map { $0.flatMap(transform) }) })
}
}