Pull request for http://jira.codehaus.org/browse/GROOVY-5414.
Adds a takeWhile method to Lists, arrays, Iterators, and CharSequences.
added takeWhile method for lists, arrays, iterators, and charsequences
Looks good, though we can probably just use Iterable instead of List
I wonder if it is good to get the elements out of the collection or Iterable two times. The first time we do it to count how many we will get out, the second time we do it to get the elements for the result. I think this should be done only once, not twice, because we never know what kind of structure we really have there and thus should have as less implicit assumptions about the used collection as possible. For example if the Collection guarantees only for one iteration that the elements are unchanged and allows in between iterations changes to them... for example some kind of crazy ring buffer... then this method will not produce the desired results
Of course it is a bit far fetched to have such a collection... I am basically just saying that this would be more on the safe side
I have a locally modified variant of this patch with a modified Iterator takeWhile that would handle the crazy ring buffer scenario but I'll play around a bit more first before pushing to github
@paulk-asert: yeah, no reason to not use Iterable. I think we should keep it consistant with take() though.
@blackdrag: that's a great point I hadn't thought of.
Added - thanks for the idea and the pull request
Work on #44 Arrays.
Work on #44. Fix variable declaration issue. Start to move predicates…
… out of grammar.
Closed #44 Fix generic array creation, and invalid handling of inner …
doc: fix wrong \' within `-elements (closes #44)