Skip to content

Instantly share code, notes, and snippets.

@zyuanming
Created October 4, 2017 15:16
Show Gist options
  • Select an option

  • Save zyuanming/d7267f46e972d65ce70e648b054ce20a to your computer and use it in GitHub Desktop.

Select an option

Save zyuanming/d7267f46e972d65ce70e648b054ce20a to your computer and use it in GitHub Desktop.
UIKonf 2017 – Day 2 – Brandon Williams & Lisa Luo – Anything you can do, I can do better
infix operator >>> : MultiplicationPrecedence
func >>> <A, B, C>(f: @escaping (A) -> B,
g: @escaping (B) -> C) -> (A) -> C {
return { g(f($0)) }
}
func incr(_ x: Int) -> Int { return x + 1 }
func square(_ x: Int) -> Int { return x * x }
let f = incr >>> square >>> incr
Array(1...10).map(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment