Balzanka / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add Iterables.shuffle #1358

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It's often useful to have a functional version of shuffle:

    private static <T> List<T> shuffle(Iterable<T> iterable)
    {
        List<T> list = Lists.newArrayList(iterable);
        Collections.shuffle(list);
        return list;
    }

Original issue reported on code.google.com by electrum on 3 Apr 2013 at 2:20

GoogleCodeExporter commented 9 years ago
I looked at 20 Google callers to Collections.shuffle. The divide about evenly 
into people who are manually cloning the list, people who really ought to be 
manually cloning the list but aren't, and people who don't need to clone it.

I'd say that a functional version of shuffle is a good thing for us to have. 
The complication is going to be in whether it's worth adding plain 
Iterables.shuffle or whether we should opt for a more powerful API that can 
choose n items with or without replacement in a streaming fashion (but special 
cases for selecting one item from RandomAccess inputs) and whatever other 
features people might want. We do have such a chooser utility internally, and 
we should consider promoting it.

Original comment by cpov...@google.com on 3 Apr 2013 at 6:29

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08