Skip to content

Instantly share code, notes, and snippets.

@sriteja25
Created July 24, 2018 13:19
Show Gist options
  • Save sriteja25/43ea302c632a0142207c407d8e1ea0b5 to your computer and use it in GitHub Desktop.
Save sriteja25/43ea302c632a0142207c407d8e1ea0b5 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