Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

Comparison between Java8 and Gura

I’ve learned that Java 8, Java’s new version, has come with features like filter() and map() methods that can handle collections more effectively. I tried writing Gura code equivalent to some Java programs with these functions to see how simple the Gura code can be than Java’s ones.

Case 1

Assume that Student is a class that has methods named getGradYear() and getScore(), which return a graduation year and an exam score respectively.

As for the program to get the maximum score of students, a list of instances of Student, who graduate in the year 2012, codes of Java and Gura come as following.


students.filter((Students s) -> s.getGradYear() == 2012)
 .map((Students s) -> s.getScore())


students.filter(students:*getGradYear() == 2012):*getScore().max()

Case 2

Assume that Star is a class that has member variable named distance.

When you use reduce() method to implement a code to get maximum distance from stars, a list of instances of Star, the codes are as following.

Java -> p.distance).reduce(0, (x, y) -> x > y ? x : y);


stars:*distance.reduce(0) {|x, y| cond(x > y, x, y)}

Using max() method, the above codes become as following.

Java -> p.distance).max().orElse(0);


stars:*distance.max() || 0

Copyright (C) 2011-2017 ypsitau