Created
January 4, 2021 13:47
-
-
Save robertofrontado/3ed85f0e3a92fb789bdfbda58c6a7d15 to your computer and use it in GitHub Desktop.
Swift Operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: - Operators | |
infix operator |> : AdditionPrecedence | |
infix operator <> : AdditionPrecedence | |
infix operator >>> : AdditionPrecedence | |
// MARK: - Implementations | |
public func |> <A, B> (a: A, f: (A) -> B) -> B { | |
return f(a) | |
} | |
public func <> <A>(_ f: @escaping (A) -> Void, | |
_ g: @escaping (A) -> Void) -> (A) -> Void { | |
return { a in | |
f(a) | |
g(a) | |
} | |
} | |
public func >>> <A, B, C>(_ a2b: @escaping (A) -> B, | |
_ b2c: @escaping (B) -> C) -> (A) -> C { | |
return { a in b2c(a2b(a)) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment