_Original issue created by electrum on 2013-04-03 at 02:20 AM_
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 comment posted by [email protected] on 2013-04-03 at 06:29 PM_
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.
Labels: Package-Collect, Type-Addition
Iterables aren't required to complete - how would that work with this?
Most helpful comment
_Original comment posted by [email protected] on 2013-04-03 at 06:29 PM_
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.
Labels:
Package-Collect,Type-Addition