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

New: CPArray -arrayByApplyingBlock: #2404

Merged
merged 2 commits into from Jan 16, 2016

Conversation

cacaodev
Copy link
Contributor

This new method maps the receiver using the provided function.
Similar to javascript or swift map function.

There are tens of places in the fmw where using this method can reduce the amount of code.

With test.

@cappbot cappbot added this to the Someday milestone Dec 28, 2015
@cappbot cappbot added the #new label Dec 28, 2015
@cappbot
Copy link

cappbot commented Dec 28, 2015

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

@cappbot
Copy link

cappbot commented Dec 29, 2015

Milestone: Someday. Labels: #needs-review, Foundation, feature. What's next? This issue is pending an architectural or implementation design decision and should be discussed or voted on.

@cacaodev
Copy link
Contributor Author

It appears that Array.map is a lot slower than for loops. An example here : https://jsperf.com/map-vs-native-for-loop/7

As a consequence, I will remove the native map but I still believe cappuccino needs a map API because it is very common in most languages.
The naming could also be better.
What about -arrayByApplyingBlock: ? More consistent with other CPArray methods naming and express better the fact that it is an immutable method. And the array prefix tells clearly what it returns.
Of course, in js Block should be Function but we already use Block for other array methods that take a function arg.
@cappuccino/core-devs what do you think ?

@aparajita
Copy link
Contributor

I agree with -arrayByApplyingBlock: as the name.

@aljungberg aljungberg modified the milestones: 0.9.9, Someday Jan 14, 2016
@aljungberg
Copy link
Member

I agree, arrayByApplyingBlock is more consistent. Methods that return something tend to be named by what they return, like arrayByAddingObject.

(Often we say UsingBlock -- arrayByUsingBlock doesn't sound as clear though. I like your naming, arrayByApplyingBlock, better.)

+#needs-improvement

@cappbot
Copy link

cappbot commented Jan 14, 2016

Milestone: 0.9.9. Labels: #needs-improvement, #needs-review, Foundation, feature. What's next?

  • This issue is pending an architectural or implementation design decision and should be discussed or voted on.
  • The code for this issue has problems with formatting or fails a capp_lint check, has bugs, or has non-optimal logic or algorithms. It should be improved upon.

@cacaodev cacaodev changed the title New: CPArray -mapUsingBlock: New: CPArray -arrayByApplyingBlock: Jan 14, 2016
@cacaodev cacaodev closed this Jan 16, 2016
@cacaodev cacaodev reopened this Jan 16, 2016
cacaodev added a commit that referenced this pull request Jan 16, 2016
New: CPArray -arrayByApplyingBlock:
@cacaodev cacaodev merged commit e172217 into cappuccino:master Jan 16, 2016
@aparajita
Copy link
Contributor

Merci!

@cacaodev
Copy link
Contributor Author

Merged, thanks for your input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants