Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow map to return objects #873

Merged
merged 1 commit into from
Oct 25, 2015
Merged

Allow map to return objects #873

merged 1 commit into from
Oct 25, 2015

Conversation

megawac
Copy link
Collaborator

@megawac megawac commented Aug 1, 2015

Map currently will attempt to assign keys to arrays and because of a bug in nodeunit this passes unit tests. I think map should either always return an array (ala lodash/underscore) for objects or do as this PR does

/cc @aearly

@megawac megawac added the bug label Aug 1, 2015
@aearly
Copy link
Collaborator

aearly commented Aug 3, 2015

I'm not sure what the "correct" thing to do here is. The way it works now is just a happy accident of using eachOf internally. I agree that map should always return arrays. Lodash returns an array when you pass an array to _.map, and has a _.mapValues function that returns an object. We could add async.mapValues (and mapValuesSeries and mapValuesLimit), but as you can see, it gets out of hand.

Once we support iterators, one thing that will be really useful is being able to have map callback with another iterator -- it will enable doing some cool stuff with lazy sequences. But perhaps we need another method for a mapping operation that keeps the type of the iterable you pass in.

@aearly
Copy link
Collaborator

aearly commented Aug 7, 2015

Another thought -- Haskell and other FP languages have the concept of an fmap function -- a function that takes a functor (basically anything that is mappable) and returns a new instance of that functor with the mapping function applied to each element. Perhaps we could call the new method async.fmap? (and fmapSeries and fmapLimit)

@aearly aearly mentioned this pull request Aug 25, 2015
aearly added a commit that referenced this pull request Oct 25, 2015
Allow map to return objects
@aearly aearly merged commit 4ad7d30 into master Oct 25, 2015
@aearly
Copy link
Collaborator

aearly commented Oct 25, 2015

Going to merge this for now, we can have map return an array later.

@megawac megawac deleted the object-map branch April 12, 2016 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants