(a)
public class Add 
extends Function.O2<Integer, Integer, Integer> { 
    private Add() {} 
    public static final Add INSTANCE = new Add(); 
    public Integer call(Integer x, Integer y) { return x + y; } 
} 


(b)
Fcn<Integer, Integer>  inc = Add.INSTANCE.x(1); 
System.out.println("Inc 5 = " + inc.x(5)); 


(c)
Transform.FcnObject<Integer, Integer> 
    incList = Transform.make(inc); 
System.out.println("inc list = " + 
    incList.x(Arrays.asList(2, 4, 8, 16, 32)) 
    .x(new LinkedList<Integer>()).toString());

Example 1: (a) The add function; (b) an increment function object, inc, would then have type Fcn<Integer, Integer>; (c) using the Transform function object.

Back to Article