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

Make @for work with any Iterable object #75

Merged
merged 2 commits into from Nov 18, 2017

Conversation

bendem
Copy link
Contributor

@bendem bendem commented Oct 21, 2017

This change makes the rocker @for syntax match the java syntax by accepting any object implementing Iterable.

I've added this as a workaround for the @for syntax not working with streams (see #40) (passing stream::iterator to the template instead of collecting to a list - and thus saving my server from high memory usage), but I'm sure others will appreciate not requiring a Collection when all that's used is the Iterable interface.

@bendem
Copy link
Contributor Author

bendem commented Oct 28, 2017

Any news on this?

@jjlauer
Copy link
Member

jjlauer commented Oct 30, 2017

Hey @bendem, sorry for missing the original github notification about this PR. I love the idea of supporting iterable (eventually streams too). Just a few issues with this PR:

  1. We need a unit test for it of something that's Iterable and not a Collection.
  2. Iterable could be supported in both Java 8 and Java 6 -- but it seems like you only added support for it in Java 8. So while adding a test for 1), make sure you add it in both the java6 and java8 modules.
  3. What about Rocker iterator support (https://github.com/fizzed/rocker/blob/master/docs/SYNTAX.md#iteration-for)? That's a key feature and I'm not sure how we support it with streams and/or iterables. Obviously, last is probably the only method that can't be supported on it. Ideally, the Java compiler would catch that if using an iterable -- vs. something like a runtime exception.

@bendem
Copy link
Contributor Author

bendem commented Oct 31, 2017

All of that makes sense, I'll try and look into it later this week.

@bendem
Copy link
Contributor Author

bendem commented Nov 11, 2017

I have replaced CollectionForIterator with IterableForIterator. That should cover all cases where rocker was using Collection instead of Iterable at once. I have not looked into Stream support (maybe another time).

@bendem
Copy link
Contributor Author

bendem commented Nov 18, 2017

Is there anything else I can do to make your review easier?

@jjlauer
Copy link
Member

jjlauer commented Nov 18, 2017

@bendem This looks good. Thanks for the contrib. Will ship it in next release.

@jjlauer jjlauer merged commit 2ecdc8c into fizzed:master Nov 18, 2017
@jjlauer
Copy link
Member

jjlauer commented Nov 20, 2017

Version 0.23.0 is released with this change. Will hit maven central in couple hours.

@bendem bendem deleted the feature/for-iterable branch November 21, 2017 21:07
@bendem
Copy link
Contributor Author

bendem commented Nov 21, 2017

Awesome, thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants