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

Add fromIterable and toNativeSet #2

Open
gabejohnson opened this issue Mar 20, 2017 · 1 comment
Open

Add fromIterable and toNativeSet #2

gabejohnson opened this issue Mar 20, 2017 · 1 comment

Comments

@gabejohnson
Copy link
Member

gabejohnson commented Mar 20, 2017

This would make it easy to convert from/to native types. fromIterable would cover any instance w/ Symbol.iterator on it.

toNativeSet would be a convenience function nearly identical to toArray.

Another option would be to make the set types iterable. Then you could just do:

const nativeDifference = fromNative => toNative => a => pipe([
  fromNative, curry2(difference)(fromNative(a)), toNative]);

const nativeDifference2 = toNative => a => pipe([
  BaseSet.fromIterable, curry2(difference)(BaseSet.fromIterable(a), toNative]);

const arrayDifference = nativeDifference(BaseSet.fromFoldable)(BaseSet.toArray);

const setDifference = nativeDifference(
  compose(BaseSet.fromFoldable, Array.from))(s => new Set(BaseSet.toArray(s)));

const arrayDifference2 = nativeDifference2(Array.from);

const setDifference2 = nativeDifference2(s => new Set(s));
@gabejohnson gabejohnson changed the title Add fromIterable and toSet Add fromIterable and toNativeSet Mar 20, 2017
@ottonascarella
Copy link

ottonascarella commented May 11, 2017

Leveraging Symbol.iterator as a default to deal with lists would probably be the best way for polymorphic reasons...even ImmutableJS uses them...

I mean: all data types that implement list-like should be implemented using iterator.

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