2015-06-09 21:28:11 +00:00
|
|
|
func <^> <T, U>(@noescape f: T -> U, a: T?) -> U? {
|
|
|
|
return a.map(f)
|
|
|
|
}
|
|
|
|
func <*> <T, U>(f: (T -> U)?, a: T?) -> U? {
|
|
|
|
return a.apply(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func >>- <T, U>(a: T?, @noescape f: T -> U?) -> U? {
|
|
|
|
return a.flatMap(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Optional {
|
|
|
|
func apply<U>(f: (Wrapped -> U)?) -> U? {
|
|
|
|
return f.flatMap { self.map($0) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 21:38:05 +00:00
|
|
|
func pure<T>(a: T) -> [T] {
|
2015-06-09 21:28:11 +00:00
|
|
|
return [a]
|
|
|
|
}
|