guava icon indicating copy to clipboard operation
guava copied to clipboard

Improve `Iterables` doc around migrating to `Stream`

Open cpovirk opened this issue 3 years ago • 3 comments

We're seeing some evidence that people are interpreting the current text as "You should always choose Stream over Iterables" and even as "Iterables is effectively deprecated."

I don't remember all the history, but at a minimum, I don't think we want to suggest "effectively deprecated," if only because of methods like mergeSorted that don't have clean Stream equivalents.

Even beyond that, I don't really see much wrong with getOnlyElement.

(On the flip side, possibly we should document an equivalent to Iterables.toString, which I think is fairly straightforward, even though it uses the 3-arg Collectors.joining, which forces you to figure out the right order of arguments.)

cpovirk avatar Dec 20 '21 19:12 cpovirk

The ongoing discussion on the linked issue reminds me of a couple other things:

  • We should specifically warn people about transform and other lazily computed views.
  • We should note that Streams.findLast can be either faster than or slower than Iterables.getLast.

cpovirk avatar Dec 21 '21 19:12 cpovirk

We should also document Maps, Sets, Lists, Multimaps, Multisets, Tables, and Collections2 to warn about lazily computed views there.

There's also an interesting question about how much to prefer methods like uniqueIndex over the Stream equivalents. (There's some discussion of this in internal bug 213183492.)

cpovirk avatar Jan 06 '22 14:01 cpovirk

what are the relevant files that I or another developer should add documentation in?

evanyang1 avatar Feb 10 '22 04:02 evanyang1