1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Free is indeed a Monad.

This commit is contained in:
Rob Rix 2015-10-02 14:03:34 -04:00
parent 97686157f3
commit 0a64dc8741

View File

@ -17,4 +17,13 @@ public enum Free<A, B> {
return .Roll(s.map { $0.map(transform) })
}
}
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) })
}
}
}