//TestSimplePipeline1.java
//Illustrates the idea of a Java "pipeline":
//source --> (zero or more) intermediate operations --> terminal operation
//This is a very powerful concept that is now available to
//us in Java 8 and and later Java versions.

import java.util.ArrayList;

public class TestSimplePipeline1
{
    public static void main(String[] args)
    {
        ArrayList<Double> nums = new ArrayList<>();
        nums.add(3.5);
        nums.add(56.3);
        nums.add(81.1);
        nums.add(4.8);

        nums.stream()
        .filter((Double val) -> val > 50) //The type of val is explicit.
        .forEach((Double val) -> System.out.println(val));
        //Here forEach() is using a lambda function as its parameter.

        System.out.println();

        //The following statement is equivalent to the above statement.
        nums.stream()
        .filter(val -> val > 50) //The type of val is "inferred".
        .forEach(System.out::println);
        //Here forEach() is using a "method reference" as its parameter.

        System.out.println();

        //Here we have no intermediate operations:
        System.out.println(nums.stream().count());
    }
}
/*  Output:
    56.3
    81.1

    56.3
    81.1

    4
*/
