This project has retired. For details please refer to its Attic page.
Core Functional API
Zest™
Introduction
Tutorials
Javadoc
Samples
Core
Libraries
Extensions
Tools
Glossary 

Core Functional API

code

docs

tests

The Zest™ Core Functional API is a generic package to work with Iterables in a "functional programming language" style.

This package is completely independent of everything else in Zest™ and may be used on its own in any kind of environment such as Spring or Java EE applications.

Table 18. Artifact

Group IDArtifact IDVersion

org.qi4j.core

org.qi4j.core.functional

2.1


First Example

Let’s say that you have an Iterable of Integers and you want to sum them all up. Most people would create a loop and sum it all up in something like this;

Iterable<Long> data = new ArrayList<Long>();
  [...snip...]


long sum = 0;
for( Long point : data )
{
    sum = sum + point;
}
System.out.println( "The sum is " + sum );

With the Zest™ Core Functional API, you go about it in a different way. The code ends up looking like this;

import static org.qi4j.functional.ForEach.forEach;
import static org.qi4j.functional.Functions.longSum;
  [...snip...]

            Iterable<Number> data = new ArrayList<Number>();
            Long sum = forEach( data ).map( longSum() ).last();
            System.out.println( "The sum is " + sum );

And this is just the tip of the iceberg.

The Big Picture

The Zest™ Core Functional API are divided a handful of powerful concepts, especially when used together;

  • Iterables - many methods to deal with Iterable data, so that the loops in your programs can largely be removed.
  • Functions - f(x) and f(x,y) are well-know from mathematics and used in functional programming languages. Zest™ is not capable of introducing lambda calculus due to limitations in Java itself, but we can simulate a lot to allow people to create more readable code.
  • Specification - A simple concept to define the bounds of data. This is used for filtering, query and many other higher level abstractions.
  • Visitor pattern - A way to be handed the items in a collection, without having the loops. This could be for end result handling, distribution of intermediary values, and many other things.

Specification

TODO

Function

TODO

Visitor Pattern

TODO

Iterables

TODO