The following is just simple filtering, I just mapping numbers and filter it in both Java8 and Ruby .... Java8 looks pretty much simple as Ruby..
Ruby:
(1..10).to_a.map {|n| n * n}.select {|n| n > 5}.each{|n| puts n}
Java8:
IntStream.rangeClosed(1, 10).map(i -> i * i).filter(i -> i > 5)
.forEach(i -> System.out.println(i));
Java8 looks very simple... (although the underlying API (stream-api) looks complex :) )
No comments:
Post a Comment