Functional Java Plus

Java adaptations of concepts from other functional languages

Лицензия

Лицензия

Категории

Категории

Java Языки программирования Functional Java Универсальные библиотеки Functional Programming
Группа

Группа

com.github.charithe
Идентификатор

Идентификатор

functional-java-plus
Последняя версия

Последняя версия

0.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Functional Java Plus
Java adaptations of concepts from other functional languages
Ссылка на сайт

Ссылка на сайт

https://github.com/charithe/functional-java-plus
Система контроля версий

Система контроля версий

https://github.com/charithe/functional-java-plus

Скачать functional-java-plus

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.functionaljava : functionaljava-java8 jar 4.3

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.mockito : mockito-core jar 1.10.19

Модули Проекта

Данный проект не имеет модулей.

Functional Java Plus

With the release of project Lambda, writing Java code in functional style has become much easier (although at times it feels like trying to parallel park a lorry in a busy town centre). Libraries like Functional Java supplement the (very limited) set of functional programming utilities in the Java standard library. However, at times even they feel inadequate if you have been working with proper functional languages like Scala or Haskell for a while. Hence, this is a set of utilities to make life easier for those who are forced to use Java but are suffering from Scala/Haskell/Rust/ withdrawal.

Releases are available in Maven Central

<dependency>
    <groupId>com.github.charithe</groupId>
    <artifactId>functional-java-plus</artifactId>
    <version>0.0.2</version>
</dependency>

Try

Something I dearly miss from Scala and Rust. Being able to succinctly express that a particular block of code could either succeed or throw an exception is very powerful in my opinion. Java standard library contains the Optional type but using it forces you to discard the error completely. FunctionalJava library provides an Either type which is the kind of disjoint union type you want but it is too generic. What you need is something like the Try in Scala or the Result in Rust -- where the "left" side is always an error type.

// Wrap a successful result
Try<String> mySuccess = Try.fromSuccess("I am a success");

// Wrap an exception
Try<String> myFailure = Try.fromFailure(new Exception("Something went wrong");

// Wrap a code block that could throw an exception
Try<String> wrapped = Try.doTry(() -> {
    // code that could throw an exception
});


// Check if the result is a success
if(myTryResult.isSuccess()){ //yay! }


//flatMap (map, filter, foreach, getOrElse, toOptional and many more are supported. See Javadoc and/or unit tests)
// This is a contrived example to illustrate flatMap functionality.
public Try<String> readStringFromFile(String fileName) {
    return Try.doTry(() -> new BufferedReader(new FileReader(fileName)))
            .flatMap((BufferedReader br) -> Try.doTry(br::readLine));
}

Версии библиотеки

Версия
0.0.2