4 ms·
I almost feel a bit gross when I have to write a "foreach" loop at this point Agreed. I've transitioned to spending most of my time in JS, and wherever I can I
by untog 13y ago
I almost feel a bit gross when I have to write a "foreach" loop at this point
Agreed. I've transitioned to spending most of my time in JS, and wherever I can I use .map(), but the chaining it's not quite the same as LINQ. Someday I intend to write a library of Array addons to provide GroupBy and so on, but I can't imagine it'll be super efficient.
- alevans4 13y agoUnderscore has groupBy and some of the others you may be looking for.
- untog 13y agoYes.. I do understand why extending the base Array object in JS is deeply frowned upon but at the same time I often wish that these sort of extensions were on the Array object. It feels clunky to use them otherwise.
- buu700 13y agoYou should check out Sugar, by far my favourite standard JS lib to use in any complex project: http://sugarjs.com/ http://sugarjs.com/
- PaulAJ 13y agoThis is the problem with doing functional list stuff in languages that permit side effects: the order of execution for each function has to be strictly defined (in both senses of the word), so the compiler can't optimise the code. In Haskell the solution (see my comment on the original page) would probably (I haven't actually checked the GHC core output) be folded into a single loop.
- aaronm67 13y agoIn Underscore, you can do something like: _([ ... ]).map( ... ).filter( ... ).value() It's not exactly extending the native array...but there are far fewer side effects to doing it this way.
- WickyNilliams 13y agoThe problem with this is that it's doing multiple iterations. LINQ on the other hand builds up an expression tree that is "compiled" into a single loop when `ToList()` (or some other method which gets the results) is eventually called.
- WickyNilliams 13y agoThis may be what you're looking for. I think it was developed my MS specifically for this reason: https://github.com/Reactive-Extensions/RxJS https://github.com/Reactive-Extensions/RxJS