essential.js
essential.js copied to clipboard
promised sequence
I tried to make minimal changes, because I like the micro-weight of essentialjs (opposed to ramda which is a whopping 1.6MB and offers a too much)
- added aliases ('pipe' and 'seq' for 'sequence') to resemble other highorder libs
- added documentation (using 'npm run-script gendoc') for README.md
- map() and filter() now support objects as well (as show in Brian Lonsdorf's talk, 'Hey Underscore, You're Doing it Wrong')
this raises the question what difference 'forOwn' kinda o
This looks great! Thanks for the good work. Let me review it in more detail.
-
Aliases: makes sense
-
Documentation: great!
-
Support for objects in map and filter: I like this in lodash myself. My question is, should all other functions like reduce, all, every, etc work with objects as well ala lodash? If that's the case, perhaps we can make a reusable HOF given that these look pretty similar:
map = ncurry 2, ->
obj = false
input = ( if isType 'Object', arguments[1] then (obj = unzipObject(arguments[1]))[1] else arguments[1] )
result = input.map arguments[0]
return ( if obj then zipObject obj[0], result else result )
filter = ncurry 2, ->
obj = false
input = ( if isType 'Object', arguments[1] then (obj = unzipObject(arguments[1]))[1] else arguments[1] )
result = input.filter arguments[0]
return ( if obj then zipObject obj[0], result else result )
Is it worth the weight? Otherwise, perhaps we name the object functions mapObject and filterObject?
-
add,mul,sub: Similar concern as above. Does this mean people are going to miss a curriedpowfor example? -
either,bindAll: I like. -
module.exports.local: I think this would make more sense as an external library. Perhaps I'm missing the point of this, but with destructuring assignment neitherexposeorlocalwould be ideal; I'd do the following:
function foo() {
var {map, filter} = _;
}
I think this would be best practice, since it is more explicit, and there is no need for globals or evaling.
3: agreed, it looks very similar.
mapandfiltercould be an shortcutfunction which calls one HOF. My preference would be to not split things up intomapObject/filterObject. I know, the general rule against it is garbage-in-garbage-out. But since its only purpose is to loop over key-based datastructures I think the sacrifice is worth the convenience.
.
Btw. I totally agree that the tiny-size of essentialjs has its beauty. Heck, the curry-ness and size is even the reason why i preferred it over lodash/lamda/underscore (uncurried or big in size) . 4: how about ditching add/mull/sub. I agree that it kinda invites future commits with
pow/divide/logetc :)
.
6: Yes that works for ES6, not for ES5. I guess we could strip out local() and put it into a gist, and reference that url in the wiki/README for ES5 users etc. The privilege to use the HOF's in local scope (without a cluttering '_' or using global scope) has been a pleasure so far imho. This might be because I secretly love the functional looks of haskell,ruby,coffeescript etc.
Btw. have you checked the mapAsync function? I've found it to be very useful, and it pretty much eliminated my need for modules like async. It gives you control over the iteration in an async way, while the traditional map or for-loop does not.