Transforms a list, applying a function to each element.
(List<? extends F> list,
java.util.function.Function<? super F, ? extends T> function)
| 2747 | |
| 2748 | /** Transforms a list, applying a function to each element. */ |
| 2749 | public static <F, T> List<T> transform(List<? extends F> list, |
| 2750 | java.util.function.Function<? super F, ? extends T> function) { |
| 2751 | if (list.isEmpty() && list instanceof ImmutableList) { |
| 2752 | return ImmutableList.of(); // save ourselves some effort |
| 2753 | } else if (list instanceof RandomAccess) { |
| 2754 | return new RandomAccessTransformingList<>(list, function); |
| 2755 | } else { |
| 2756 | return new TransformingList<>(list, function); |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | /** Transforms a list, applying a function to each element, also passing in |
| 2761 | * the element's index in the list. */ |