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
Add {Iterables, Iterators}.{dropWhile, takeWhile} #619
Comments
Original comment posted by j...@nwsnet.de on 2011-05-11 at 01:46 PM Hm, the lists worked well when tested with the [http://fossil.wanderinghorse.net/demos/wikiwym/GoCoWi-previewer.html Wikiym] live preview. Maybe someone privileged can fix them to regain readability? Also, the side note got quite long. Might be a good idea to copy it to a separate ticket if there is interest in it. |
Original comment posted by gscerbak on 2011-05-11 at 04:26 PM I thought before about such a list (how come you missed out the Lisp?:)...), but I think most of the time it would be quite misleading. If you take a source e.g. in Haskell, translate it using such a list, the result might not behave as the Haskell version. I think the details of guava implementation and Java semantics make it specific enough for a library userto take the effort of learning what is what and how it works. |
Original comment posted by ogregoire on 2011-05-11 at 04:33 PM I think it's identical to issue 477. |
Original comment posted by j...@nwsnet.de on 2011-05-11 at 07:13 PM gscerbak: The list is not meant to offer drop-in replacements, but as a kick-starter for new Guava users with a sufficient background in dealing with collections/iterables. Looking closer is always a must; fortunately, the Guava docs are quite insightful, detailed, and prepare against pitfalls. ogregoire: So you're reponsible for that (to my knowledge) pretty uncommon naming of |
Original comment posted by cgdecker on 2011-05-11 at 08:18 PM @yo.gi: I think names like "skip" and "limit" were chosen because they're good names for those methods. Precedent from other languages isn't a good enough reason to use a name, particularly if that name doesn't actually fit well with the behavior of a method. The names "take" and "drop", for example, both imply an active removal of elements... the actual behavior of those methods is to "limit" the size of an iterable and to "skip" the first elements of an iterable. Status: |
Original comment posted by j...@nwsnet.de on 2011-05-11 at 09:16 PM Your basic argument is valid, of course. Excuse my trace of conservatism :) Which names are suitable is debatable, though. "limit" can be interpreted as modifying the underlying data, too (in the sense of truncation). I think it depends on the point of view one chooses. When considering the data to operate with as on-the-fly, speaking of "modifying" seems very appropriate to me. Also, "transform", "partition" and "reverse" don't operate in-place in Guava, too (although one could think so, ignoring the return type). Actually, when it comes to However, as "skip" and "limit" are already in place, sticking to those IMHO is the wisest option anyway. Not my first choice (principle of least surprise is violated here, I'd say from my experience with common naming in this domain), and it might underline the usefulness a mapping like the one I outlined above, but hey. |
Original issue created by j...@nwsnet.de on 2011-05-11 at 01:42 PM
I miss methods to skip/retrieve the first elements of an Iterable according to a predicate (i.e. the predicate is used to determine the index at which an Iterable is partitioned, then the first/second partition is returned).
On a side note: I'd welcome a wiki page which maps Guava's methods and their names to common names in order to help people easily find methods (also to find them missing, as in this case) under names they know (e.g. from various programming languages or libraries).
E.g. (what I can recall from Guava, Haskell, Scala, Python, and Ruby):
*
any
,exists
*
all
,forall
*
filter
,select
*
transform
,map
,collect
*
fold*
,reduce*
,inject
*
find
*
limit
,take
*
takeWhile
*
skip
,drop
*
dropWhile
*
concat
,chain
*
zip
*
partition
,grouped
*
slice
*
uniqueIndex
,groupBy
etc.
Some references:
* [http://www.cse.unsw.edu.au/~en1000/haskell/hof.html]
* [http://www.scala-lang.org/api/current/scala/collection/Iterable.html]
* [http://docs.python.org/library/itertools.html#module-itertools]
* [http://code.google.com/p/fluentjava/wiki/EnumerationProtocol]
* [http://wiki.squeak.org/squeak/uploads/SqueakClassesRef.html#Enumerating%20Collections]
* [http://www.ruby-doc.org/core/]
The text was updated successfully, but these errors were encountered: