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

Express flatMap with analysis.

This commit is contained in:
Rob Rix 2015-10-02 14:36:01 -04:00
parent b4479e3854
commit e4d0a41093

View File

@ -32,12 +32,7 @@ public enum Free<A, B> {
// MARK: Monad
public func flatMap<C>(@noescape transform: B -> Free<A, C>) -> Free<A, C> {
switch self {
case let .Pure(b):
return transform(b)
case let .Roll(s):
return .Roll(s.map { $0.flatMap(transform) })
}
return analysis(ifPure: transform, ifRoll: { .Roll($0.map { $0.flatMap(transform) }) })
}
}