Skip to content

Commit e1eceb9

Browse files
committed
Update Iterables.
1 parent ef8c55a commit e1eceb9

4 files changed

Lines changed: 7 additions & 789 deletions

File tree

README.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,6 @@ public static <T> Iterable<T> filter(Iterable<T> iterable, Predicate<? super T>
11421142
public static <T> T firstOf(Iterable<T> iterable) { ... }
11431143

11441144
public static <T> boolean exists(Iterable<T> iterable, Predicate<? super T> predicate) { ... }
1145-
1146-
public static <T, R> R collect(Iterable<T> iterable, Function<Iterable<T>, R> collector) { ... }
11471145
```
11481146

11491147
These are provided as a less complex alternative to similar methods defined by the `java.util.stream.Stream` class:
@@ -1179,65 +1177,3 @@ var values = listOf(1, 2, 3);
11791177

11801178
var result = exists(values, value -> value < 3); // true
11811179
```
1182-
1183-
```java
1184-
var values = listOf("a", "bc", "def");
1185-
1186-
var result = collect(values, iterable -> {
1187-
var stringBuilder = new StringBuilder();
1188-
1189-
for (var element : iterable) {
1190-
stringBuilder.append(element);
1191-
}
1192-
1193-
return stringBuilder.toString();
1194-
}); // abcdef
1195-
```
1196-
1197-
The following standard collection functions are included:
1198-
1199-
```java
1200-
public static <T> Function<Iterable<T>, Integer> toSum(ToIntFunction<T> transform) { ... }
1201-
public static <T> Function<Iterable<T>, Long> toSum(ToLongFunction<T> transform) { ... }
1202-
public static <T> Function<Iterable<T>, Double> toSum(ToDoubleFunction<T> transform) { ... }
1203-
1204-
public static <T> Function<Iterable<T>, Double> toAverage(ToIntFunction<T> transform) { ... }
1205-
public static <T> Function<Iterable<T>, Double> toAverage(ToLongFunction<T> transform) { ... }
1206-
public static <T> Function<Iterable<T>, Double> toAverage(ToDoubleFunction<T> transform) { ... }
1207-
1208-
public static <T> Function<Iterable<T>, Integer> toMinimum(ToIntFunction<T> transform) { ... }
1209-
public static <T> Function<Iterable<T>, Long> toMinimum(ToLongFunction<T> transform) { ... }
1210-
public static <T> Function<Iterable<T>, Double> toMinimum(ToDoubleFunction<T> transform) { ... }
1211-
1212-
public static <T> Function<Iterable<T>, Integer> toMaximum(ToIntFunction<T> transform) { ... }
1213-
public static <T> Function<Iterable<T>, Long> toMaximum(ToLongFunction<T> transform) { ... }
1214-
public static <T> Function<Iterable<T>, Double> toMaximum(ToDoubleFunction<T> transform) { ... }
1215-
1216-
public static <T extends Comparable<? super T>> Function<Iterable<T>, T> toMinimum() { ... }
1217-
public static <T extends Comparable<? super T>> Function<Iterable<T>, T> toMaximum() { ... }
1218-
1219-
public static <T> Function<Iterable<T>, T> toMinimum(Comparator<? super T> comparator) { ... }
1220-
public static <T> Function<Iterable<T>, T> toMaximum(Comparator<? super T> comparator) { ... }
1221-
1222-
public static <T, K> Function<Iterable<T>, Map<K, List<T>>> groupingBy(Function<? super T, ? extends K> classifier) { ... }
1223-
```
1224-
1225-
For example:
1226-
1227-
```java
1228-
var values = listOf(1, 2, 3, 4, 5);
1229-
1230-
var result = collect(values, toSum(Integer::intValue)); // 15
1231-
```
1232-
1233-
```java
1234-
var values = listOf("a", "b", "c", "d", "e");
1235-
1236-
var result = collect(values, toMinimum()); // a
1237-
```
1238-
1239-
```java
1240-
var values = listOf("a", "b", "ab", "bc", "abc");
1241-
1242-
var result = collect(values, groupingBy(String::length)); // 1: a, b; 2: ab, bc; 3: abc
1243-
```

0 commit comments

Comments
 (0)