Proposal: Selector/Select Expression

Simon Farrugia simonfarrugia26 at gmail.com
Fri Jun 21 11:49:26 UTC 2019


Selector/Select Expression



Doing functional & reactive programming is currently really verbose in
JavaScript.

Hopefully this issue will be alleviated with the addition of the pipe
operator in the near future.



One things you end up doing most when doing fp is doing simple selections
(mappings) on objects & arrays. This unfortunately becomes really verbose
and repetitive.



What I'm proposing is to be able to collapse/simplify selector arrow
function expressions like this:



```

// user => email

const getEmail = user => user.contacts.email;

```



to something like this:



```

// user => email

const getEmail = .contacts.email;

```



More examples:



```

// user[] => email[] (With Arrays)

const getEmailsList = users => users.map(user => user.contacts.email);

const getEmailsList = .map(.contacts.email);

```



```

// Usage with pipeline operator

pipe(user, map(user => user.contacts.email))

user |> .contacts.email

```



I think this would work really well, particularly in conjunction with the
pipeline operator, resulting in more concise and expressive code improving
readability.

This is just syntactic sugar, but same as in the case of the pipeline
operator, selector functions are so intrinsic and commonplace to any code
base, that I would think it's worth considering.



I would  appreciate hearing your thoughts. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190621/9c3894a9/attachment-0001.html>


More information about the es-discuss mailing list