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

Support for other types that implement Symbol.iterator #7

Open
RaederDev opened this issue Mar 7, 2018 · 3 comments
Open

Support for other types that implement Symbol.iterator #7

RaederDev opened this issue Mar 7, 2018 · 3 comments

Comments

@RaederDev
Copy link
Contributor

Hi!

Would be a super awesome feature if the library would also support types other than plain Arrays that implement Symbol.iterator. If the library would use for ... of internally this could be fairly easy to implement for most methods.

@toniov
Copy link
Owner

toniov commented Mar 8, 2018

Thanks for the issue!

Yeah being able to use other JS iterable objects should be nice.

At the beginning I just wanted to keep it simple, as a replacement for ES5 Array methods.
Other reason I kept it this way is that some of p-iteration methods maybe doesn't make sense for other iterable objects apart from Array.

What do you think about it? Does it make sense to you, for example, using map() with a Set?

Releasing a version 2.0.0 changing the API is also an option I've been thinking about.

@RaederDev
Copy link
Contributor Author

I think most methods would make sense for most supported data-types.
You could have a Set of userIds and want to map them to a Set of Users for example.

await map(new Set([1, 2]), async uid => await fetchUser(uid));

I'm sure there are some cases where it doesn't make sense at all, but people often have strange use-cases. Especially map and forEach make sense for almost everything.

The reason I opened the issue is because I wanted to use the library to iterate over a Map like this:

const orders = new Map();
orders.set('o1', {superSecretData: 42});
orders.set('o2', {superSecretData: 42});

await forEach(orders, async ([,val]) => await sendToServer(val));

If you think about releasing a version 2.0, maybe it would also be a nice idea to switch the order of function and data to data last like lodash/fp does it. That way it would be very easy to partially apply a function for later use.

const logToServer = forEach.bind(null, async data => {
    await Promise.resolve('Server API dummy function ' + data);
});

logToServer([1, 2]);
logToServer([3, 4]);

@toniov
Copy link
Owner

toniov commented May 19, 2018

Thanks for your opinion and sorry for the super late reply.

I think that definitely I'll make it compatible with the rest of types.

If you think about releasing a version 2.0, maybe it would also be a nice idea to switch the order of function and data to data last like lodash/fp does it. That way it would be very easy to partially apply a function for later use.

This looks good but I would add it as an option (similar to lodash/fp), because I think that that order would be unfamiliar to most of the people.

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

2 participants