0

Never seen this one before:

.flatMap(obj => {
        return removeOneLine(this)
            .map(l => {l:l,id:obj.id});

I want to map the result, but of course, I guess JS doesn't know if this is an object or the function body.

Is doing the following the only way to avoid a syntax error (because it's ambiguous to the engine):

  .flatMap(obj => {
           return removeOneLine(this)
                .map(l => {
                    return {l: l, id: obj.id}
                });
        })

is this ambiguity in this situation normal, any way to mitigate besides what I just did above?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • Btw, you changed two things in your code, you removed the `return` keyword. It's unclear if that's just a "typo" or part of your actual change. Either way it's completely unrelated to the problem. – Felix Kling Dec 29 '16 at 06:03
  • sorry, I didn't mean to remove that return statement, edited, thanks – Alexander Mills Dec 29 '16 at 06:05

1 Answers1

1

Why do you have the curlies for a single-statement fat-arrow function?

You don't need curly braces around the function bodies or an explicit return statement. You do, however, need to put parentheses around the object literal to prevent its being interpreted as a function body.

.flatMap( obj=> removeOneLine(this).map(l => ({ l: l, id: obj.id })) )
Mark Reed
  • 91,912
  • 16
  • 138
  • 175