Skip to content

Instantly share code, notes, and snippets.

@jarsen
Last active August 29, 2015 14:07
Show Gist options
  • Save jarsen/0199022f050a701e313c to your computer and use it in GitHub Desktop.
Save jarsen/0199022f050a701e313c to your computer and use it in GitHub Desktop.
decisions, decisions...
extension Int {
class func add1(x: Int) -> Int {
return x + 1
}
func add2() -> Int {
return self + 2
}
}
func add3(x: Int) -> Int {
return x + 3
}
// disadvantage of preferring class methods
Int.add1(1)
1.add2()
// advantage of preffering class methods
[1,2,3].map(Int.add1)
[1,2,3].map { x in x.add2() }
// advantage of preferring functions
add3(1)
[1,2,3].map(add3) // wow. much functional.
// disadvantage: other people may hate and fear you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment