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

Set and Get methods #8

Closed
rt2zz opened this issue Jul 19, 2016 · 4 comments
Closed

Set and Get methods #8

rt2zz opened this issue Jul 19, 2016 · 4 comments

Comments

@rt2zz
Copy link

rt2zz commented Jul 19, 2016

Libraries that work with iterables often need to get or set values by key or index. Would it make sense for iterall to support get & set?

@leebyron
Copy link
Owner

Can you explain a bit more how you would expect this to work?

@rt2zz
Copy link
Author

rt2zz commented Jul 19, 2016

Case in point we have a long standing issue to support immutablejs map as state for redux-persist. Rather than make a special case for Map, it would be nice to be able to drop in iterall to support any type of iterable.

To do this we would need get and set, e.g.:

var get = require('iterall').get
var set = require('iterall').set

//...
state = state.set('fooReducer', 'bar')
var foo = state.get('fooReducer')

Of course this assumes we treat all iterables as immutable which is a bit opinionated...

I do not have an easy solution, but if get & set were part of the protocol I think redux-persist and likely many other projects would be eager to adopt.

@leebyron
Copy link
Owner

leebyron commented Jul 20, 2016

state = state.set('fooReducer', 'bar')
var foo = state.get('fooReducer')

This example assumes set and get are prototype methods on whatever state is. What would they look like for the versions that are imported?

And I'm still a bit confused. I'm not sure I understand how you're thinking get and set might be implemented or how they should behave for any given Iterable.

Consider:

function* infiniteBlue() {
  while (true) {
    yield "blue";
  }
}

var iterable = infiniteBlue();

// get?
// set?

What would get and set do with this? What would be the API you imagine and what behavior would you expect?

@rt2zz
Copy link
Author

rt2zz commented Jul 20, 2016

Ah sorry, in my example I meant for it to be get(state, 'fooReducer') rather than a prototype method.

Nevertheless, your point is taken that not all iterables have a concept of "keys".

@rt2zz rt2zz closed this as completed Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants