How do I understand the signature list in CoffeeScript?

I have the following line CoffeeScript:

names = (mail.folder for mail in @data when mail.service_name is service.name).unique()

This line is too long, so it will not jump to linting on CoffeeLint.

I try to break it, but I always get indentation errors on CoffeeLint.

What is the right way to do this?

+5
source share
3 answers

This is the most readable version, not too long:

names =
  (for mail in @data when mail.service_name is service.name
    mail.folder).unique()

You cannot split transitions across multiple lines, but a normal loop can also return a value, so using one of them solves the problem. If you are ready to provide an extra line, there is no need for uncomfortable parentheses around the loop:

names =
  for mail in @data when mail.service_name is service.name
    mail.folder
names = names.unique()

, for ; , , :

names =
(for mail in @data when mail.service_name is service.name
  mail.folder).unique()
+5

:

names = (mail.folder for mail in @data \
         when mail.service_name is service.name).unique()

for ... when :

names = (for mail in @data when mail.service_name is service.name
           mail.folder).unique()
+4

Apparently splitting lists into multiple lines is not allowed:

fooobar.com/questions/1118252 / ...

0
source

All Articles