Created
June 23, 2018 10:56
-
-
Save H-Ghadirian/db16ca5e8596c6cd85ea44e2ee91f412 to your computer and use it in GitHub Desktop.
Forward Pipe |> operator
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
infix operator |> { precedence 50 associativity left } | |
// Pipe forward: transform "x |> f" to "f(x)" and "x |> f |> g |> h" to "h(g(f(x)))" | |
public func |> <T,U>(lhs: T, rhs: T -> U) -> U { | |
return rhs(lhs) | |
} | |
//Without the forward pipe | |
let convertedImage = convertToGrayscale(image: adjustColors(image: image)) | |
//With the forward pipe operator | |
let convertedImage = image |> adjustColors |> convertToGrayscale |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment