5 ms·
Show HN: Dollar and Cent – A functional tool belt for Swift
- agp2572 12y agoDollar 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 12y agoits 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 12y agoThe plan is to implement extensions as well.
- randomguy7788 12y agothat is awesome to hear!
- MrGando 12y agoHate this stuff, Swift != Javascript.
- ankurpatel 12y agoHaters 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 12y agoA lot of these functions transcend javascript, and are a product the functional world.
- Nekorosu 12y agoIt's not Objective C also. Move on. The new world awaits. Though dollar swift is a little bit cheesy for my taste.
- MrGando 12y agoA little bit cheesy? People should file Apple radars if they there's functionality missing in a Beta Language. Not just try to catch attention and stars in Github with useless (at least in this stage) projects. PS: I insist, an expressive language like Swift doesn't need '$.' Cheers.
- ankurpatel 12y agoMrGando I felt '$.' was needed to avoid less typing for developers while at the same time introducing a namespace that doesn't conflict with anything in the developers project. Namespace is needed to avoid conflicts with function names as those same functions could be defined inside another function or class causing compiler errors when building. Before calling this project useless please consider the alternative which is none. Apple will take its time even if you tell them to implement these. You can either implement these helper methods yourself or you can use this or another library. Out of the thousands of people who saw this and liked it I expect few haters like you cause "If people don't hate then it won't be right"
- Nekorosu 12y agoI have a feeling MRGando means the library doesn't look idiomatic enough. Though this meaning is lost behind the tone of the message.
- Nekorosu 12y agoWell... actually you have a good point about some projects existing mostly (if not only) for self-promotion purpose. Talking about Swift's expressiveness. After skimming through Apple's Swift book I tend to agree with you. I misunderstood your first comment having a thought you wanted Swift code to be more like Objective C.
- GuiA 12y agofirst 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?
- agp2572 12y agoIs Rail's ActiveSupport a joke? https://github.com/rails/rails/blob/a31277011814b7bdb6be41a807e14d6bf2852620/activesupport/lib/active_support/core_ext/array/access.rb#L57 https://github.com/rails/rails/blob/a31277011814b7bdb6be41a8...
- p4lindromica 12y agoI think the specific example you gave actually is a joke. http://www.quora.com/Why-is-Array-forty_two-called-the-reddit-in-Ruby-on-Rails http://www.quora.com/Why-is-Array-forty_two-called-the-reddi...
- ankurpatel 12y agoYes it is :)
- Karunamon 12y agoNot 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 :)
- sanderjd 12y agoIt'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.
- vilya 12y agoI 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?
- lsdafjklsd 12y agoNot 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).