You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspired by my answer in a stackoverflow question, I came up with append, an operator enhancer (or HOO🦉 if you will) that keeps the original value of the source. Source posted in my gist.
I think it could be useful for those cases where you want to map/switchMap/etc. the value to something else, but you need to keep in the original value for later use.
To use it, you just wrap any existing operator with it:
And do not worry, if your original value was an array, it will nest it as if it was a regular value (so it won't return a flat array with your values in it + the one returned by the operator):
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Inspired by my answer in a stackoverflow question, I came up with
append
, an operator enhancer (or HOO🦉 if you will) that keeps the original value of the source. Source posted in my gist.I think it could be useful for those cases where you want to map/switchMap/etc. the value to something else, but you need to keep in the original value for later use.
To use it, you just wrap any existing operator with it:
And it also has a perk! you can chain as many
append
as you want, and it won't build up nested arrays:And do not worry, if your original value was an array, it will nest it as if it was a regular value (so it won't return a flat array with your values in it + the one returned by the operator):
(It uses a
symbol
to flag what arrays are appendable and which ones aren't. Another possibility would be to use a WeakSet instead).And, of course, full typescript support. It uses tuple types, so you can have different types and it will work when destructuring those tuples.
Beta Was this translation helpful? Give feedback.
All reactions