Reputation: 324
I'm looking at the following code
var results = _(items).groupBy((i) => i.key))
.map((group, key) => { return { key: key, group: group } })
.value();
line 2 bothers the hell out of me as I feel that I should be able to do it like line 1 (the one that does not use a return). What would be the syntax to do that?
Upvotes: 0
Views: 92
Reputation: 250036
The problem is that the syntax is ambiguous between an arrow function that returns an object literal and one that has a block, the spec decided to just interpret p => {
as an arrow function with block not an arrow function with an object literal. You can easily get around this with some ()
:
var results = _(items).groupBy((i) => i.key))
.map((group, key) => ({ key: key, group: group }))
.value();
Upvotes: 1