added takeWhile method for lists, arrays, iterators, and charsequences #44

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

Pull request for http://jira.codehaus.org/browse/GROOVY-5414.

Adds a takeWhile method to Lists, arrays, Iterators, and CharSequences.

Member

Looks good, though we can probably just use Iterable instead of List

Member

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

@paulk-asert paulk-asert was assigned Apr 23, 2012
Member

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.

Member

Added - thanks for the idea and the pull request

@blackdrag blackdrag pushed a commit that referenced this pull request Aug 27, 2014
@xSeagullx xSeagullx Work on #44 Arrays. 1b04193
@blackdrag blackdrag pushed a commit that referenced this pull request Aug 27, 2014
@xSeagullx xSeagullx Work on #44. Fix variable declaration issue. Start to move predicates…
… out of grammar.
13d2562
@blackdrag blackdrag pushed a commit that referenced this pull request Aug 27, 2014
@xSeagullx xSeagullx Closed #44 Fix generic array creation, and invalid handling of inner …
…generics list.
bbcf630
@melix melix pushed a commit to melix/groovy-core that referenced this pull request Jul 9, 2015
@christoph-frick @PascalSchumacher christoph-frick + PascalSchumacher doc: fix wrong \' within `-elements (closes #44) a8313c3
@melix melix pushed a commit to melix/groovy-core that referenced this pull request Jul 9, 2015
@christoph-frick @PascalSchumacher christoph-frick + PascalSchumacher doc: fix wrong \' within `-elements (closes #44) b3baf64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment