Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active February 11, 2017 04:20
Show Gist options
  • Save saoudrizwan/6335737d7f6b56dcc7fac8d58e7a0f0f to your computer and use it in GitHub Desktop.
Save saoudrizwan/6335737d7f6b56dcc7fac8d58e7a0f0f to your computer and use it in GitHub Desktop.
extension Int {
func doMath(_ transform: ((Int) -> (Int)) ) -> (Int) {
return transform(self)
}
}
let doubled = 5.doMath { (number) -> (Int) in
return number * 2
}
print(doubled) // 10
let minusOne = 8.doMath { $0 - 1 }
print(minusOne) // 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment