node-options
node-options copied to clipboard
Would you accept a PR for .tap ?
:)
As in a function that behaves as
const tap = (option, f) => option.map(value => (f(value), value));
? Could you give some examples of when this might be useful?
Exactly :)
It's useful for mutation (sometimes needed) and debugging purpose.
e.g.:
option.tap(val => val.x += 1).valueOrElse(0);
My preference is to use map in a separate statement. This keeps the API smaller, and makes the flow of data clearer without having to understand tap.
option.map(val => val.x += 1);
const value = option.valueOrElse(0);
Indeed, one could always mimic .tap behaviour using map but my request concerns code flow & conciseness, it's not a must have but a very good nice to have and every time I use this library, I miss it :)