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

Optimize unfold/unfoldLeft for Lists #2688

Closed
tvelka opened this issue Sep 29, 2021 · 1 comment
Closed

Optimize unfold/unfoldLeft for Lists #2688

tvelka opened this issue Sep 29, 2021 · 1 comment

Comments

@tvelka
Copy link

tvelka commented Sep 29, 2021

At the moment the List::unfold and List::unfoldLeft are implemented as Iteartor.unfoldLeft(...).toList() which works but perhaps a better implementation would be

return Iterator.unfoldRight(seed, f.andThen(tupleOpt -> tupleOpt.map(Tuple2::swap)))
               .foldLeft(List.empty(), List::prepend);

This builds the result without any additional reverse() operations and Streams in a single for-loop.

@danieldietrich
Copy link
Contributor

Hi, improving the implementations is always welcome! Are you volunteering for a PR?

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