Created
October 4, 2012 02:53
-
-
Save mainyaa/3831200 to your computer and use it in GitHub Desktop.
This is Functional Programming on Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Integer> listI = list(1, list(2, list(3, list(4, list(5, list(6, emptyList())))))); | |
Integer sum = listI.filter(new Function1<Integer, Boolean>() { | |
public Boolean apply(Integer i){ return i % 2 == 0; } | |
}) | |
.map(new Function1<Integer, Integer>() { | |
public Boolean apply(Integer i) { return i * 2; } | |
}) | |
.foldLeft(0, new Function2<Integer, Integer, Integer>(){ | |
public Integer apply(Integer seed, Integer item){ return seed + item; } | |
}); | |
assertEquals(new Integer(24, sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment