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

Fmap #13

Merged
merged 5 commits into from
Dec 12, 2014
Merged

Fmap #13

merged 5 commits into from
Dec 12, 2014

Conversation

kkazuo
Copy link
Contributor

@kkazuo kkazuo commented Dec 6, 2014

It's inspired from Haskell's fmap.
An array's fmap returns a new array, and a dictionary's fmap returns a new dictionary not an array.

@mxcl
Copy link
Owner

mxcl commented Dec 8, 2014

Seems that NSArray.fmap is the same as NSArray.map? In which case we should just make it an alias rather than duplicate the code.

@kkazuo
Copy link
Contributor Author

kkazuo commented Dec 9, 2014

Partially yes. But fmap preserves container class's mutability. map does not.

NSArray @[x, y, z].fmap(f) returns NSArray @[f(x), f(y), f(z)]
NSMutableArray @[x, y, z].fmap(f) returns NSMutableArray @[f(x), f(y), f(z)]

return type of NSArray.fmapshould be (instancetype *(^)(id)), if I could.

@mxcl
Copy link
Owner

mxcl commented Dec 9, 2014

I think probably this is a bug in map.

@kkazuo
Copy link
Contributor Author

kkazuo commented Dec 9, 2014

OK.
NSMutableDictionary.map returns NSArray instead of NSMutableArray.
Do you think this is bug too? or only NSArray.map has bug?

@mxcl
Copy link
Owner

mxcl commented Dec 10, 2014

In the case of the dictionary map it is hard to know if the originating dictionary is mutable or not. I've tried to write such code. So in that case we can just return an NSArray IMO, as it doesn't matter since the type is different anyway.

@kkazuo
Copy link
Contributor Author

kkazuo commented Dec 10, 2014

Now, NSArray.fmap is alias of NSArray.map.
And little tweak on NSArray.map.

mxcl added a commit that referenced this pull request Dec 12, 2014
@mxcl mxcl merged commit 05f1fa2 into mxcl:master Dec 12, 2014
@kkazuo
Copy link
Contributor Author

kkazuo commented Dec 12, 2014

Thank you!

@kkazuo kkazuo deleted the fmap branch December 12, 2014 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants