functional-java

functional-java is an object oriented library which provides functional APIs for different data-structures.

License

License

Categories

Categories

Java Languages Functional Java General Purpose Libraries Functional Programming
GroupId

GroupId

io.github.senthilganeshs
ArtifactId

ArtifactId

functional-java
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

functional-java
functional-java is an object oriented library which provides functional APIs for different data-structures.
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/senthilganeshs/functional-java

Download functional-java

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.senthilganeshs/functional-java/ -->
<dependency>
    <groupId>io.github.senthilganeshs</groupId>
    <artifactId>functional-java</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.senthilganeshs/functional-java/
implementation 'io.github.senthilganeshs:functional-java:1.0.0'
// https://jarcasting.com/artifacts/io.github.senthilganeshs/functional-java/
implementation ("io.github.senthilganeshs:functional-java:1.0.0")
'io.github.senthilganeshs:functional-java:jar:1.0.0'
<dependency org="io.github.senthilganeshs" name="functional-java" rev="1.0.0">
  <artifact name="functional-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.senthilganeshs', module='functional-java', version='1.0.0')
)
libraryDependencies += "io.github.senthilganeshs" % "functional-java" % "1.0.0"
[io.github.senthilganeshs/functional-java "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.openjdk.jmh : jmh-core jar 1.20
org.openjdk.jmh : jmh-generator-annprocess jar 1.20

test (2)

Group / Artifact Type Version
junit : junit jar 3.8.1
org.testng : testng jar 6.14.3

Project Modules

There are no modules declared in this project.

build

functional-java

Functional Java is an initiative to bring functional APIs to JAVA without compromizing on object oriented programming principes.

Maven repository https://mvnrepository.com/artifact/io.github.senthilganeshs/functional-java/1.0.0

<!-- https://mvnrepository.com/artifact/io.github.senthilganeshs/functional-java -->
<dependency>
    <groupId>io.github.senthilganeshs</groupId>
    <artifactId>functional-java</artifactId>
    <version>1.0.0</version>
</dependency>

Features

This is just a start and came out of preparing content for this blog

The functional API's are influenced from Haskell which is a pure functional language.

Following data-structures are supported as of now.

  1. List
  2. Maybe
  3. Tuple
  4. Either
  5. BinaryTree (Set)

Examples

List.of(1,2,3,4,5).take(2);
> [1, 2]

List.of(1,2,3,4,5).drop(2);
> [3, 4, 5]

List.of(1,2,3,4,5).reverse();
> [5, 4, 3, 2, 1]

List.of("+91","123","456","7890").intersperse("-").foldl("", this::concat);
> +91-123-456-7890

List.of(1,2,3,4,5,6,7,8).filter(i -> i % 2 == 0);
> [2,4,6,8]

List.of(1,2,3).map (i -> i * 2);
> [2, 4, 6]

Maybe.some(5).concat(List.of(1,2,3,4))
> [1,2,3,4,5]

List.of(1,4,9).concat(BinaryTree.of(3))
> { Label : 3, left = { Label : 1, left = [], right = [] }, right = { Label : 4, left = [], right = { Label : 9, left = [], right = [] } } }

List.of(1,2,3).flatMap(i -> (i < 3) ? Maybe.some(i) : Maybe.nothing());
> Nothing

List.of(1,2,3).flatMap(i -> (i <=3) ? Maybe.some(i) : Maybe.nothing());
> [1,2,3]

List.of(1,2,3).apply(List.of(i -> i +1, i -> i + 2));
> [2, 3, 4, 3, 4, 5]

List.of(1,2,3).apply(Maybe.some(i -> i + 1));
> Some(4)

List.of(1,2,3).traverse(i -> Maybe.some(i + 1));
> Some ([2,3,4])

List.of(1,2,3).traverse (i -> List.of('a', 'b'));
> [[a,a,a],[b,a,a],[a,b,a],[b,b,a],[a,a,b],[b,a,b],[a,b,b],[b,b,b]]

Iterable.sequence(List.of(1,2,3).traverse(i -> Maybe.some(i + 1)));
> [Some (2),Some (3),Some (4)]

Iterable.sequence(Iterable.sequence(List.of(1,2,3).traverse(i -> Maybe.some(i + 1))));
> Some ([2, 3, 4])

Iterable.lefts(List.of(Either.right(1), Either.left(2), Either.right(3)))
> [2]

Iterable.rights(List.of(Either.right(1), Either.left(2), Either.right(3)))
> [1, 3]

Iterable.partition(List.of(Either.right(10), Either.left(20), Either.right(30)))
> ([20], [10,30])

BinaryTree.of(3,1,2,5,4).contains(2)
> true

List.of(3,1,2,5,4).sort()
> [1, 2, 3, 4, 5]

Tuple.of ('a', 1).swap()
> (1, a)

List.of(1,2).zipper()
> ([1,2], )

Iterable2.goForward(List.of(1,2).zipper())
> ([1], [2])

Iterable2.goForward(Iterable2.goForward(List.of(1,2).zipper()))
> (, [2,1])

Iterable2.goBack(Iterable2.goForward(List.of(1,2).zipper()))
> ([1,2], )

Versions

Version
1.0.0