Posted almost 7 years ago. Visible to the public. Deprecated.

You don't need each, collect or select in Coffeescript

JavaScript's Array class now has forEach(), map() and filter().

We also don't write so much CoffeeScript anymore.

Working with lists in Javascript is painful because the native Array class is so poorly designed.

One way to reduce the pain is to to use Underscore.js's functions like _.each, or, which unfortunately clutters your code with awkward calls to the _ helper.

Fortunately when you use CoffeeScript you don't need any of that. CoffeeScript has a very versatile for keyword that can do anything that each, collect or select can do. Enjoy!


for item in items ...

collect / map

ages = (person.age for person in people)

select / grep

adults = (person for person in people when person.age >= 18)

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Henning Koch
Last edit:
24 days ago
by Henning Koch
list, comprehensions
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more