Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upsert #1118

Open
char0n opened this issue Oct 14, 2019 · 1 comment
Open

upsert #1118

char0n opened this issue Oct 14, 2019 · 1 comment

Comments

@char0n
Copy link
Owner

char0n commented Oct 14, 2019

Is your feature request related to a problem? Please describe.

Polymorphic updating or inserting in one operation. We're using ad hoc polymorphism here.

Describe the solution you'd like

// working on objects
upsert('key', () => 'new value', () => 'initial value', {}); // {key: 'initial value'}
upsert('key', () => 'new value', () => 'initial value', {key: 'value'}); // {key: 'new value'}

// working on arrays
upsert(1, () => 'new value', () => 'initial value', []); // sparse array of [, 'initial value']
upsert(1, () => 'new value', () => 'initial value', ['first value', 'second vaue']); // ['first value', 'new value']

// working on maps
upsert('key', () => 'new value', () => 'initial value', new Map()); // Map({key: 'initial value'})
upsert('key', () => 'new value', () => 'initial value', new Map([['key', 'new value']])); // Map({key: 'new value'})

Describe alternatives you've considered

--

Additional context

TC39 Map.upsert proposal: https://github.com/tc39/proposal-upsert (stage 2 proposal). Our version of polymorhic upsert can work on multiple JavaScript types.

@char0n
Copy link
Owner Author

char0n commented Dec 28, 2019

We discussed the viability of this function with TC39 proposal author and he agrees the function make sense if the library (R, RA) already support polymorphic functions.

@char0n char0n removed their assignment Jan 21, 2020
@char0n char0n added the Hacktoberfest Hacktoberfest 2020 label Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant