Hate this implicit return statement. Proposal to add returnless function arrow

Hello guys! Thank you for creating and supporting CoffeeScript!

Often when I want to extract loop to separate method I write like this:

performEach = ->
  el.perform() for el in collection

But always getting loop which collects returned data from el.perform():

var performEach;

performEach = function() {
  var el, i, len, results;
  results = [];
  for (i = 0, len = collection.length; i < len; i++) {
    el = collection[i];
    results.push(el.perform());
  }
  return results;
};

Then I add explicit return statement:

performEach = ->
  el.perform() for el in collection; return

And getting what I want:

var performEach;

performEach = function() {
  var el, i, len;
  for (i = 0, len = collection.length; i < len; i++) {
    el = collection[i];
    el.perform();
  }
};

Proposal! What do you think about returnless arrow? Something like this:

performEach = |> # Note new syntax: "|>". Fat arrow syntax: "||>" 
  el.perform() for el in collection

Compiles to:

var performEach;

performEach = function() {
  var el, i, len;
  for (i = 0, len = collection.length; i < len; i++) {
    el = collection[i];
    el.perform();
  }
};

For many APIs is it important what value was returned (for example it is event handlers in jQuery).
Also there is article about it http://programmaticallyspeaking.com/why-i-hate-implicit-return-in-coffeescript.html

1 possible answer(s) on “Hate this implicit return statement. Proposal to add returnless function arrow

  1. This has been asked and rejected more times than I can remember off hand.

    In 99%% of cases, you either want the last statement of the function to be the return value, or the return value is thrown away and it doesn’t matter.

    For the remaining 1%% of cases, you can type return at the end of the function, which is much more explicit about your intent, and less complex than Yet Another Operator.

    Can people PLEASE stop asking for this not-a-feature now?