Commits

Micha Kops committed 1263ebd

functionaljava: examples for functions of different arity added.

  • Participants
  • Parent commits 85d673e

Comments (0)

Files changed (1)

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

+package com.hascode.tutorial;
+
+import static fj.data.Array.array;
+import fj.Effect;
+import fj.F;
+import fj.F2;
+
+public class DifferentArityFunctionsExample {
+	public static void main(final String[] args) {
+		F<String, Boolean> endsWithX = new F<String, Boolean>() {
+			@Override
+			public Boolean f(final String a) {
+				return a.endsWith("x");
+			}
+		};
+
+		F2<String, String, Boolean> stringsEqual = new F2<String, String, Boolean>() {
+			@Override
+			public Boolean f(final String a, final String b) {
+				return a.equals(b);
+			}
+
+		};
+		// output: "barx bazx"
+		array("foo", "barx", "moo", "bazx").filter(endsWithX).foreach(output);
+	}
+
+	static Effect<String> output = new Effect<String>() {
+		@Override
+		public void e(final String a) {
+			System.out.println(a);
+		}
+	};
+}