Commits

Micha Kops  committed 67d796e

functionaljava: Applying function on each list element example added.

  • Participants
  • Parent commits 1263ebd

Comments (0)

Files changed (2)

File src/main/java/com/hascode/tutorial/ApplyingFunctionPerListElementExample.java

+package com.hascode.tutorial;
+
+import static fj.data.Array.array;
+import static fj.function.Integers.multiply;
+
+public class ApplyingFunctionPerListElementExample {
+	public static void main(final String[] args) {
+		// multiplies each element in the array with 1 and adds the results
+		int result = array(1, 2, 3, 5).foldLeft(multiply, 1);
+		System.out.println(result); // 30
+	}
+}

File src/main/java/com/hascode/tutorial/DifferentArityFunctionsExample.java

 			}
 		};
 
+		// output: "barx bazx"
+		array("foo", "barx", "moo", "bazx").filter(endsWithX).foreach(output);
+
 		F2<String, String, Boolean> stringsEqual = new F2<String, String, Boolean>() {
 			@Override
 			public Boolean f(final String a, final String b) {
 			}
 
 		};
-		// output: "barx bazx"
-		array("foo", "barx", "moo", "bazx").filter(endsWithX).foreach(output);
 	}
 
 	static Effect<String> output = new Effect<String>() {