DEV Community

Discussion on: ELI5 - "Map-filter-reduce"

Collapse
 
evanoman profile image
Evan Oman • Edited

Java 8+

-> IntStream.range(0,10).                         
>> map(xs -> xs*xs).                              
>> filter(xs -> xs % 2 == 0).                     
>> reduce(0, (xs_1, xs_2) -> xs_1 + xs_2)         
|  Expression value is: 120                       
|    assigned to temporary variable $7 of type int

Scala

scala> (0 to 9).          
     | map(xs => xs*xs).  
     | filter(_ % 2 == 0).
     | reduce(_+_)        
res0: Int = 120

Note: Both Java and Scala have sum methods on these objects which would be equivalent the reduce I used above.

Collapse
 
isaacleimgruber profile image
IsaacLeimgruber

Is scala popular now?