Funava

Partial function application paradigm in Java

License

License

GroupId

GroupId

io.jmnarloch
ArtifactId

ArtifactId

funava
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Funava
Partial function application paradigm in Java
Project URL

Project URL

https://github.com/jmnarloch/funava.git
Source Code Management

Source Code Management

https://github.com/jmnarloch/funava.git

Download funava

How to add to project

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

Dependencies

test (2)

Group / Artifact Type Version
org.mockito : mockito-all jar 1.10.19
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Funava

Small Java library for partial function application.

Build Status

Funava is implemented without a single Java class.

Setup

Currently only as snapshot available from: https://oss.sonatype.org/content/repositories/snapshots/

<dependency>
    <groupId>io.jmnarloch</groupId>
    <artifactId>funava</artifactId>
    <version>0.2.0</version>
</dependency>

Examples

Safe cast

Object val = "test";

String result =  SafeCast.cast(val).to(String.class).orElse("default");

// result == test

Ternary operator

int i = 15;

int result = Condition.when(i % 2 == 0).then(i / 2).orElse(i * 3);

// i == 45

Partial function application

public String url(String scheme, String host, int port, String username, String repo) {
    return String.format("%s://%s:%d/%s/%s", scheme, host, port, username, repo);
}

String url = Partial.function(this::url)
                .arg("https")
                .arg("github.com")
                .arg(443)
                .arg("jmnarloch")
                .apply("funava");

// url == https://github.com:443/jmnarloch/funava

public int sum(int a, int b) {
        return a + b;
}

int sum = Partial.function(this::sum)
                .arg(1)
                .apply(2);

// 1 + 2 == 3

public int substract(int a, int b) {
        return a - b;
}

int diff = Partial.function(this::substract)
                .rarg(2)
                .apply(1);

// 1 - 2 == -1

public int product(int a, int b) {
        return a * b;
}
    
int product = Partial.function(this::product)
                .arg(4)
                .apply(5);

// 4 * 5 == 20

License

Apache 2.0

Versions

Version
0.2.0
0.1.0