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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)