Last active
August 29, 2015 14:07
-
-
Save jarsen/0199022f050a701e313c to your computer and use it in GitHub Desktop.
decisions, decisions...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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