Skip to content

Instantly share code, notes, and snippets.

@Qata
Created March 30, 2016 22:28
Show Gist options
  • Save Qata/1fda86c1fb09b9df1752b21f9251bc29 to your computer and use it in GitHub Desktop.
Save Qata/1fda86c1fb09b9df1752b21f9251bc29 to your computer and use it in GitHub Desktop.
infix operator <<< { associativity right }
func <<< <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
return composeBackward(f, g: g)
}
infix operator >>> { associativity left }
func >>> <A, B, C>(g: A -> B, f: B -> C) -> A -> C {
return composeForward(g, f: f)
}
func composeBackward <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
return { x in f(g(x)) }
}
func composeForward <A, B, C>(g: A -> B, f: B -> C) -> A -> C {
return { x in f(g(x)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment