|
| 1 | +# SimpleStream |
| 2 | +SimpleStream makes it easier to use Java 8 Streams by reducing the amount of boilerplate code required to perform common tasks. |
| 3 | + |
| 4 | +````java |
| 5 | +import static simplestream.SimpleStream.stream; |
| 6 | + |
| 7 | +Collection<Integer> values = Arrays.asList(1, 5, 2, 4, 3); |
| 8 | + |
| 9 | +/* Simpler collector methods */ |
| 10 | +stream(values).map(x -> x + 1).toList(); // [2, 6, 3, 5, 4] |
| 11 | + |
| 12 | +/* Less confusing filtering */ |
| 13 | +stream(values).select(x -> x % 2 == 0).toList(); // [2, 4] |
| 14 | +stream(values).remove(x -> x % 2 == 0).toList(); // [1, 5, 3] |
| 15 | + |
| 16 | +/* Comparison operations (for streams of Comparable elements) */ |
| 17 | +stream(values).min(); // 1 |
| 18 | +stream(values).max(); // 5 |
| 19 | +stream(values).sort().toList(); // [1, 2, 3, 4, 5] |
| 20 | + |
| 21 | +/* Numeric operations (for streams of numbers) */ |
| 22 | +stream(values).sumAsInt(); // 15 |
| 23 | +stream(values).average(); // 3.0 |
| 24 | + |
| 25 | +/* Miscellaneous operations */ |
| 26 | +stream(values).groupBy(x -> x % 2 == 0 ? "even" : "odd"); // {even=[2, 4], odd=[1, 5, 3]} |
| 27 | +stream(values).contains(4); // true |
| 28 | +stream(values).join("+"); // "1+5+2+4+3" |
| 29 | +```` |
| 30 | + |
| 31 | +SimpleStream is distributed in source form and contains a single source file (<code>SimpleStream.java</code>) that can be directly included in your project. You can download the latest release [here](https://github.com/lmadhavan/simplestream/releases). |
0 commit comments