package lambdasinaction.chap4;
import java.util.stream.*;
import java.util.*;

import static lambdasinaction.chap4.Dish.menu;

public class Reducing{

    public static void main(String...args){
    
        List<Integer> numbers = Arrays.asList(3,4,5,1,2);
        int sum = numbers.stream().reduce(0, (a, b) -> a + b);
        System.out.println(sum);
        
        int sum2 = numbers.stream().reduce(0, Integer::sum);
        System.out.println(sum2);
        
        int max = numbers.stream().reduce(0, (a, b) -> Integer.max(a, b));
        System.out.println(max);
        
        Optional<Integer> min = numbers.stream().reduce(Integer::min);
        min.ifPresent(v -> System.out.println(v));
    

        int calories = menu.stream()
                           .map(Dish::getCalories)
                           .reduce(0, Integer::sum);
        System.out.println("Number of calories:" + calories);
    }
}

@@ -188,21 +188,17 @@
 .args)%7B%0A
-    
 %0A
+
         
@@ -343,25 +343,17 @@
 n(sum);%0A
-        
 %0A
+
         
@@ -439,25 +439,17 @@
 (sum2);%0A
-        
 %0A
+
         
@@ -552,17 +552,9 @@
 x);%0A
-        
 %0A
+
     
@@ -646,13 +646,8 @@
 ent(
-v -%3E 
 Syst
@@ -656,26 +656,19 @@
 .out
-.
+::
 println
-(v));%0A    
+);
 %0A%0A  

tidy up