Click here to Skip to main content
15,891,864 members
Articles / Programming Languages / Java

Functional Java

Rate me:
Please Sign up or sign in to vote.
4.11/5 (6 votes)
7 Dec 2010CPOL8 min read 39.7K   284   14  
Functional programming with functors and object streams in Java.
package swensen.functional;

/**
 * A Tuple2 implementation representing a grouping by key
 * @param <E> the element type
 */
public class Grouping<R,E> extends Tuple2<R,Seq<E>> {
    public Grouping(R key, Seq<E> grouping) {
        super(key, grouping);
    }

    /**
     * Create a Grouping tuple from the given key (t1) and grouping (t2).
     * @param key the grouping key
     * @param grouping the grouping
     * @param <R> the key type
     * @param <E> the grouping type
     * @return a new Grouping
     */
    public static <R,E> Grouping<R,E> create(R key, Seq<E> grouping) {
        return new Grouping(key,grouping);
    }

    /**
     * A helper naming this.t1 as "key"
     * @return this.t1
     */
    public R getKey() {
        return t1;
    }

    /**
     * A helper naming this.t2 as "grouping"
     * @return this.t2
     */
    public Seq<E> getGrouping() {
        return t2;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I'm developing Unquote, a library for writing unit test assertions as F# quoted expressions: http://code.google.com/p/unquote/

I am working through Project Euler with F#: http://projecteulerfun.blogspot.com/

I participate in Stack Overflow: http://stackoverflow.com/users/236255/stephen-swensen

Comments and Discussions