Giter Club home page Giter Club logo

funk's Introduction

Funk Build Status

Simplifying functional programming in Java.

Description

Funk is a library of functional utilities to aid in writing Java in a functional style. It currently supports the following main features:

  • Lazy and eager higher order functions for manipulating collections such as map, reduce, zip, filter, take and drop.
  • A full suite of function interfaces for representing different arities of functions, predicates and procedures.
  • Collection literals and builders for assembling collections from various sources.
  • Monadic types such as Option and Either.
  • Generically typed tuples of different lengths for representing arbitrary records in a type safe manner.
  • Generators for generating potentially infinite streams of objects satisfying particular semantics.

Examples

One of the most commonly used features of Funk is the collection manipulation functions. As an example, consider an online catalogue that contains a collection of Product instances. Each product instance has a number of associated Variant instances representing different colours or sizes. To obtain a collection containing all possible variants, we first need to map each Product to its collection of Variants:

Iterable<Product> products = database.getAllProducts();
Iterable<Iterable<Variant>> productVariants = Lazily.map(products, new Mapper<Product, Iterable<Variant>>() {
  @Override public Iterable<Variant> map(Product product) {
    return product.getVariants();
  }
});

Once we have the Variant collections, to obtain a flattened collection of those variants, we need to concatenate:

Iterable<Variant> allVariants = Iterables.concat(productVariants);

And finally, to get the set of all unique variants, we can convert the Iterable to a Set:

Set<Variant> uniqueVariants = Literals.setFrom(allVariants);

Whilst this example is slightly contrived, this manner of collection manipulation is common in many different use cases. It is important to note:

  • The mapping is performed lazily as is the concatenation of the Iterable instances. Thus, no collection manipulation is actually performed until the Iterable is iterated to construct the final Set.
  • All operations leave the input collections unchanged and represent pure functions.

For more information see the project wiki or the Javadoc documentation.

Binary Releases

The latest released version of Funk is 0.1.13 which can be obtained from Maven Central.

Planned Features

The highest priority future features are outlined below:

  • Full Javadoc documentation of the public API (required before 1.0).
  • Extended collection interfaces and implementations to allow a more fluid approach to performing collection manipulations for those projects that prefer not to use static methods so frequently.
  • Immutability as a first class concern.
  • Function base classes and manipulation methods such as composition and partial evaluation.

Contributions

Funk is always looking for contributors so if you find it useful please consider fixing an issue. The issue page is used to track all feature requests and bugs. To contribute, fork the main repository, make your changes on a branch and make a pull request from that branch.

Contributors

See the contributors page.

License

The BSD License.

funk's People

Contributors

akiellor avatar brunns avatar tobyclemson avatar tomcz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.