Skip to content

alexengrig/lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda

Maven Central Javadocs GitHub

Add-ons for java.util.function.

TerConsumer:

TerConsumer<byte[], Integer, Integer> fn = (byte[] bytes, Integer offset, Integer length) -> new String(bytes, offset, length);
TerConsumer<byte[], Integer, Integer> ref = String::new;

TerFunction:

TerFunction<String, Integer, Integer, String> fn = (String s, Integer b, Integer e) -> s.substring(b, e);
TerFunction<String, Integer, Integer, String> ref = String::substring;

TerPredicate:

TerPredicate<Long, Long, Long> predicate3 = (f, s, t) -> f > 0 ^ s > 0 ^ t > 0;

ConsumerCurrying:

List<String> list = new LinkedList<>();
Stream.of("1", "2", "3")
              // s -> list.add(0, s)
        .forEach(ConsumerCurrying.left2(list::add, 0));
String value = String.join("", list);
assert "321".equals(value);

FunctionCurrying:

String value = Stream.of("1", "22", "333")
          // s -> s.substring(0, 1)
        .map(FunctionCurrying.right3(String::substring, 0, 1))
        .collect(Collectors.joining());
assert "123".equals(value);

PredicateCurrying:

String value = Stream.of("-Task", "-Test", "-Text")
             // s -> s.startsWith("Te", 1)
        .filter(PredicateCurrying.right3(String::startsWith, "Te", 1))
        .collect(Collectors.joining());
assert "-Test-Text".equals(value);

See full code in demo.

Install

Gradle

implementation 'dev.alexengrig:lambda:2.0'

Maven

<dependency>
    <groupId>dev.alexengrig</groupId>
    <artifactId>lambda</artifactId>
    <version>2.0</version>
</dependency>

License

This project is licensed under Apache License, version 2.0.