infix operator <*> {
associativity left
precedence 100
}
infix operator > {
associativity left
precedence 100
}
infix operator <~~ {
associativity left
precedence 110
}
infix operator <<~ {
associativity left
precedence 110
}
func <*>(f: (A -> B)?, x: A?) -> B? {
guard let f = f, x = x else {
return nil
}
return f(x)
}
func >(f: (A? -> B)?, x: A?) -> B? {
guard let f = f else {
return nil
}
return f(x)
}
func <~~(x: A?, f: (A -> B?)) -> B? {
guard let x = x else {
return nil
}
return f(x)
}
func <<~(x: [A]?, f: (A -> B?)) -> [B]? {
guard let x = x else {
return nil
}
return x.map(f).flatMap{ $0 }
}