Giter Site home page Giter Site logo

dukererenst / totallylazy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pydawan/totallylazy

0.0 1.0 0.0 3.87 MB

Another functional library for Java

Home Page: https://totallylazy.com/

License: Apache License 2.0

Shell 0.07% Java 99.93% HTML 0.01%

totallylazy's Introduction

totallylazy

Another functional library for Java

Friendly support is available at our Google Group or post a question on StackOverflow with tag totallylazy

A functional library for Java that has the following features

  • Tries to be as lazy as possible just like Clojure's collection library
  • Works with Iterable, Iterator, Arrays, Char Sequences, Dates and Numbers (i.e virtually everything)
  • Follows the ML family of function / method names (Standard ML, oCaml, F#, Scala, Haskell)
  • Uses and extends Callable interface for maximum interop (i.e Can use with Clojure, Hazelcast)
  • Optionally supports using Hamcrest matchers as predicates
  • Supports chaining of all methods (Recommended) or the use of static imports for all methods.
  • Contains PersistentSet, PersistentMap, PersistentSortedMap, PersistentList
  • Support Functors and Applicative Functors
  • Supports runtime multi-method dispatch and pattern matching

Tail call optimisation is available in conjunction with JCompilo

Now also available in Objective-C

Examples

The following are some simple examples of actual Java code (minus any imports). They are using numbers just to make them simple but these could just as well be any types; though you would either need to create some strongly types predicates / callables for your types or use the provided dynamic proxy support.

sequence(1, 2, 3, 4).filter(even); // lazily returns 2,4
sequence(1, 2).map(toString); // lazily returns "1", "2"
sequence(1, 2).mapConcurrently(toString); // lazily distributes the work to background threads
sequence(1, 2, 3).take(2); // lazily returns 1,2
sequence(1, 2, 3).drop(2); // lazily returns 3
sequence(1, 2, 3).tail(); // lazily returns 2,3
sequence(1, 2, 3).head(); // eagerly returns 1
sequence(1, 2, 3).reduce(sum); // eagerly return 6
sequence(1, 3, 5).find(even); // eagerly returns none()
sequence(1, 2, 3).contains(2); // eagerly returns true
sequence(1, 2, 3).exists(even); // eagerly return true
sequence(1, 2, 3).forAll(odd); // eagerly returns false;
sequence(1, 2, 3).foldLeft(0, add); // eagerly returns 6
sequence(1, 2, 3).toString(); // eagerly returns "1,2,3"
sequence(1, 2, 3).toString(":"); // eagerly returns "1:2:3"

Generators

range(1, 4); // lazily returns 1,2,3,4
repeat("car"); // lazily returns an infinite sequence of "car"s
iterate(increment, 1); // lazily returns 1,2,3 ... to infinity
range(1, 4).cycle(); // lazily returns 1,2,3,4,1,2,3,4,1,2,3,4 infinitely 
primes(); // lazily returns every prime number
fibonacci(); // lazily returns the fibonacci sequence
powersOf(3); // lazily returns the powers of 3 (i.e 1,3,9,27 ...)

Naturally you can combine these operations together ...

iterate(increment, 1).filter(even).take(10).reduce(average); // returns 11

And because all the operations except reduce are lazy the sequence of numbers is only processed once.


Releases

  • Stable releases are version 1.x (Require Java 7+) Branch:java7
  • Development releases are version 2.x (Require Java 8+) HEAD

All releases are created automically and released to

http://repo.bodar.com/com/googlecode/totallylazy/totallylazy/

This is a maven repository so you can just add the following in you repo section

<repositories>
    <repository>
        <id>repo.bodar.com</id>
        <url>http://repo.bodar.com</url>
    </repository>
</repositories>

and then

<dependencies>
    <dependency>
        <groupId>com.googlecode.totallylazy</groupId>
        <artifactId>totallylazy</artifactId>
        <version>SOME_VERSION</version>
    </dependency>
</dependencies>

License

Apache 2

Sponsors

YourKit is kindly supporting open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications.Take a look at !YourKit's leading software products: YourKit Java Profiler YourKit .NET Profiler

totallylazy's People

Contributors

danielbodart avatar savagematt avatar raymanoz avatar spmiller avatar kwasniew avatar ajluker avatar thomasalanlee avatar rhyskeepence avatar daviddenton avatar jazzatola avatar jooyunghan avatar mneedham avatar ponzao avatar serverbodarcom avatar

Watchers

James Cloos 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.