Read more

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

Henning Koch
September 28, 2013Software engineer at makandra GmbH

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.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

One way to reduce the pain is to to use Underscore.js Show archive.org snapshot 's functions like _.each, _.map or _.select, 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 Show archive.org snapshot that can do anything that each, collect or select can do. Enjoy!

each

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)
Posted by Henning Koch to makandra dev (2013-09-28 18:46)