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

adapt functions to functional style (iterable last) #21

Closed
xgbuils opened this issue Jun 28, 2017 · 3 comments
Closed

adapt functions to functional style (iterable last) #21

xgbuils opened this issue Jun 28, 2017 · 3 comments

Comments

@xgbuils
Copy link
Owner

xgbuils commented Jun 28, 2017

Currently, iterum library use functions inspired by lodash. However, after reading more about functional programming and knowing another libraries like imlazy, ramda or lodash/fp, I prefer iterables in the last parameter.

@xgbuils
Copy link
Owner Author

xgbuils commented Jun 28, 2017

However I will mantain the methods having two ways to operate with iterables. I mean:

Iterum([1, 2, 3]).map(e => 2 * e) // method style
Iterum.map(e => 2 * e, [1, 2, 3]) // functional style

@xgbuils xgbuils added this to the release 2.0 milestone Jun 28, 2017
xgbuils added a commit that referenced this issue Jun 29, 2017
@xgbuils
Copy link
Owner Author

xgbuils commented Jun 30, 2017

This change produce some inconvenients for binary iterable functions like concat and zip.

For the almost functions we have this rule:

Iterum(iterable).map(cb) === Iterum.map(cb, iterable)
Iterum(iterable).reduce(cb, initial) === Iterum.reduce(cb, initial, iterable)
Iterum(iterable).padEnd(length, value) === Iterum.padEnd(length, value, iterable)

But if this rule is extrapolated to zip function we have:

Iterum(firstIterable).zip(secondIterable) === Iterum.zip(secondIterable, firstIterable)

Then Iterum.zip([1, 2], [3, 4]) returns

[
    [3, 1],
    [4, 2]
]

But it's not the intuitive result. Then, I should think more how to handle this type of functions.

@xgbuils
Copy link
Owner Author

xgbuils commented Jun 30, 2017

Fixed!

@xgbuils xgbuils closed this as completed Jun 30, 2017
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