The sequence class allows you to build up a computation out of smaller operations.
It's very similar to Java 8 Streams but has hundreds more methods and uses explicit parallelism (which tends to be better for IO operations).
It has methods from Clojure, Scala, Haskell and F#.
Bring in some static imports:
import static com.googlecode.totallylazy.Sequences.*; // Where the sequence factory methods live;
import static com.googlecode.totallylazy.Callables.*; // Lots of helper functions;
import static com.googlecode.totallylazy.numbers.Numbers.*; // Used for working with Numbers
Now we can try some of the following:
sequence(1, 2, 3, 4).filter(even); // lazily returns 2,4
sequence(1, 2).map(toString); // lazily returns "1", "2"
sequence(1, 2).mapConcurrently(toString); // lazily distributes the work to background threads
sequence(1, 2, 3).take(2); // lazily returns 1,2
sequence(1, 2, 3).drop(2); // lazily returns 3
sequence(1, 2, 3).tail(); // lazily returns 2,3
sequence(1, 2, 3).head(); // eagerly returns 1
sequence(1, 2, 3).reduce(sum); // eagerly return 6
sequence(1, 3, 5).find(even); // eagerly returns none()
sequence(1, 2, 3).contains(2); // eagerly returns true
sequence(1, 2, 3).exists(even); // eagerly return true
sequence(1, 2, 3).forAll(odd); // eagerly returns false;
sequence(1, 2, 3).fold(0, sum); // eagerly returns 6
sequence(1, 2, 3).toString(":"); // eagerly returns "1:2:3"
100+ more methods...