Skip to content

Instantly share code, notes, and snippets.

@H-Ghadirian
Created June 23, 2018 10:56
Show Gist options
  • Save H-Ghadirian/db16ca5e8596c6cd85ea44e2ee91f412 to your computer and use it in GitHub Desktop.
Save H-Ghadirian/db16ca5e8596c6cd85ea44e2ee91f412 to your computer and use it in GitHub Desktop.
Forward Pipe |> operator
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