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

Con-splat-enate Arrays #123

Merged
merged 2 commits into from
Nov 26, 2014
Merged

Con-splat-enate Arrays #123

merged 2 commits into from
Nov 26, 2014

Conversation

nonsensery
Copy link
Contributor

What's this PR do?

Adds a section to the "Concatenating Arrays" chapter that uses the splat operator (...) in an array literal ([]) to concatenate arrays.

For example:

array1 = [1, 2, 3]
array2 = [4, 5, 6]
array3 = [array1..., array2...]

The Discussion section currently says that "CoffeeScript lacks a special syntax for joining arrays". I think you could argue that there is a special syntax for joining arrays, and this is it.

This pattern also has some nice features like:

  • It's highly readable.
  • It scales easily and clearly to multiple arrays. [array1..., array2..., array3...]
  • It allows other non-array elements to be interspersed. [array1..., value1, value2, array2...]

CoffeeScript allows you to concatenate arrays by splatting them into an array literal. This change adds a section describing that option.
I hope that's not too presumptuous for such a small change.
sukima added a commit that referenced this pull request Nov 26, 2014
@sukima sukima merged commit d2c97b2 into coffeescript-cookbook:master Nov 26, 2014
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