FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Java
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
November 01, 2005

Functional Programming in Java

(Page 2 of 3)
November, 2005: Functional Programming in Java

(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.

Previous Page | 1 | 2 | 3 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK