The reason it isn’t working is because you are returning an object, which has such similar syntax to a function that it breaks. So to make it work you wrap it in a function like so:
If you are simply returning an object from an arrow function, you need to enclose the object’s curly braces inside parentheses, otherwise the Javascript interpreter will interpret the opening curly brace as a code block (as in if (true) { code } or for (;;) { code }).
So:
movie => ({title: movie.Title, rating: movie.imdbRating})
I guess that depends on your definition of elegance. It is certainly more explicit about what it is doing, but I don’t think that necessarily implies inelegance.
The concept of elegance in comp sci is one that is rooted in mathematics. Its heart is simplicity (which isn’t a special use case, if you ask google:
Elegance
the quality of being graceful and stylish in appearance or manner; style.
the quality of being pleasingly ingenious and simple; neatness.
I think that arrow functions are inarguably elegant, in that they use an arrow to map from: domain => range, describing the very concept of a function visually. For the hot concept of functional programming, the extra visual clutter reduces readability to anyone trained in mathematics and computation.
Elegance in Comp Sci covers elegance of syntax and elegance of algorithm. You gain nothing in the second by using return and lose something from the first.