top | item 7967182

Show HN: Dollar and Cent – A functional tool belt for Swift

55 points| agp2572 | 11 years ago |github.com

24 comments

order
[+] GuiA|11 years ago|reply
first Returns the first element in the array and terminated the chain

second Returns the second element in the array and terminated the chain

third Returns the third element in the array and terminated the chain

fourth Returns the fourth element in the array and terminated the chain

fifth Returns the fifth element in the array and terminated the chain

sixth Returns the sixth element in the array and terminated the chain

seventh Returns the seventh element in the array and terminated the chain

eighth Returns the eighth element in the array and terminated the chain

ninth Returns the ninth element in the array and terminated the chain

tenth Returns the tenth element in the array and terminated the chain

... is this a joke?

[+] sanderjd|11 years ago|reply
It's pretty interesting to compare the extent to which different libraries take this idea. I think tenth is the furthest I've seen. I find first and last useful frequently, but I think the furthest of these ordinals I've ever used in real code was second or maybe third.
[+] Karunamon|11 years ago|reply
Not really, it's just a way to make your code more expressive in a different way, I can see it helping in some cases since arrays are zero-indexed.

arr.first is more immediately expressive to me than arr[0] - but this is a matter of opinion :)

[+] agp2572|11 years ago|reply
Dollar is a Swift library that provides useful functional programming helper methods without extending any built in objects. It is similar to Lo-Dash or Underscore in Javascript.

Cent is a library that extends certain Swift object types using the extension feature like ActiceSupport in ruby and gives its two cents to Swift language.

[+] randomguy7788|11 years ago|reply
its unfortunate that it repeats the same mistakes that underscore and lodash does (imo) and makes it very hard to do composition (data comes in first instead of the predicate/function)
[+] ankurpatel|11 years ago|reply
The plan is to implement extensions as well.
[+] lsdafjklsd|11 years ago|reply
Not so much functional as just useful methods for working with arrays / maps. It would be functional to include a compose method... also currying is going to be painful because of how the arguments are structured (data first).
[+] vilya|11 years ago|reply
I don't understand why every result is stored into the same class-level variable. What's the aim behind that? It just seems like it would introduce unexpected behaviour without any gain, but I don't really know swift yet so maybe there's something I'm missing?
[+] agp2572|11 years ago|reply
Static methods are defined using class keywork.
[+] MrGando|11 years ago|reply
Hate this stuff, Swift != Javascript.
[+] ankurpatel|11 years ago|reply
Haters gonna hate :)

But really functions are first class citizens in Swift and it is designed to be a hybrid between OO and functional programming language. It doesn't implement some of the common helper functions like pluck, difference, intersection, etc. This is where this or another library comes in.

[+] jaxytee|11 years ago|reply
A lot of these functions transcend javascript, and are a product the functional world.
[+] Nekorosu|11 years ago|reply
It's not Objective C also. Move on. The new world awaits.

Though dollar swift is a little bit cheesy for my taste.