Created
May 11, 2019 19:18
-
-
Save amadeu01/90e7b335524635ee4204a50f48d5cbe0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //swiftlint:disable identifier_name redundant_void_return | |
| precedencegroup ForwardApplication { | |
| associativity: left | |
| } | |
| infix operator |>: ForwardApplication | |
| public func |> <A, B>(x: A, f: (A) -> B) -> B { | |
| return f(x) | |
| } | |
| public func |> <A: AnyObject>(x: A, f: (A) -> Void) -> Void { | |
| f(x) | |
| } | |
| precedencegroup EffectfulComposition { | |
| associativity: left | |
| higherThan: ForwardApplication | |
| } | |
| infix operator >=>: EffectfulComposition | |
| public func >=> <A, B, C>( | |
| _ f: @escaping (A) -> (B, [String]), | |
| _ g: @escaping (B) -> (C, [String]) | |
| ) -> ((A) -> (C, [String])) { | |
| return { a in | |
| let (b, logs) = f(a) | |
| let (c, moreLogs) = g(b) | |
| return (c, logs + moreLogs) | |
| } | |
| } | |
| precedencegroup ForwardComposition { | |
| associativity: left | |
| higherThan: EffectfulComposition | |
| } | |
| infix operator >>>: ForwardComposition | |
| public func >>> <A, B, C>( | |
| f: @escaping (A) -> B, | |
| g: @escaping (B) -> C | |
| ) -> ((A) -> C) { | |
| return { a in g(f(a)) } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment