MCPcopy Index your code
hub / github.com/bodar/totallylazy

github.com/bodar/totallylazy @2.287

Chat with this repo
repository ↗ · DeepWiki ↗ · release 2.287 ↗ · + Follow
5,185 symbols 22,717 edges 597 files 53 documented · 1% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

Extension points exported contracts — how you extend this code

Memory (Interface)
(no doc) [6 implementers]
src/com/googlecode/totallylazy/Memory.java
Animal (Interface)
(no doc) [2 implementers]
test/com/googlecode/totallylazy/SequenceTest.java
Second (Interface)
(no doc) [8 implementers]
src/com/googlecode/totallylazy/Second.java
Projection (Interface)
(no doc)
test/com/googlecode/totallylazy/collections/SelectionTest.java
Key (Interface)
(no doc) [9 implementers]
src/com/googlecode/totallylazy/Key.java
Aggregate (Interface)
(no doc)
test/com/googlecode/totallylazy/collections/SelectionTest.java
Foldable (Interface)
(no doc) [14 implementers]
src/com/googlecode/totallylazy/Foldable.java
Segment (Interface)
(no doc) [7 implementers]
src/com/googlecode/totallylazy/Segment.java

Core symbols most depended-on inside this repo

assertThat
called by 1923
src/com/googlecode/totallylazy/Assert.java
is
called by 1434
src/com/googlecode/totallylazy/Option.java
sequence
called by 679
src/com/googlecode/totallylazy/parser/Parser.java
pair
called by 333
src/com/googlecode/totallylazy/parser/Parsers.java
map
called by 234
src/com/googlecode/totallylazy/Functor.java
hasExactly
called by 227
src/com/googlecode/totallylazy/matchers/NumberMatcher.java
parse
called by 182
src/com/googlecode/totallylazy/parser/Parser.java
value
called by 154
src/com/googlecode/totallylazy/Value.java

Shape

Method 4,401
Class 627
Interface 136
Enum 21

Languages

Java100%

Modules by API surface

test/com/googlecode/totallylazy/SequenceTest.java121 symbols
src/com/googlecode/totallylazy/Sequences.java99 symbols
src/com/googlecode/totallylazy/Sequence.java95 symbols
src/com/googlecode/totallylazy/Iterators.java73 symbols
src/com/googlecode/totallylazy/numbers/Numbers.java63 symbols
test/com/googlecode/totallylazy/json/PersistentJsonRecordTest.java55 symbols
test/com/googlecode/totallylazy/proxy/ProxyTest.java53 symbols
src/com/googlecode/totallylazy/functions/Callables.java53 symbols
src/com/googlecode/totallylazy/predicates/Predicates.java49 symbols
src/com/googlecode/totallylazy/io/Uri.java45 symbols
src/com/googlecode/totallylazy/xml/Xml.java44 symbols
test/com/googlecode/totallylazy/json/JsonRecordTest.java41 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add totallylazy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page