when

Simple Pattern Matching

Лицензия

Лицензия

Группа

Группа

io.github.ufukhalis
Идентификатор

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

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

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

0.0.6
Дата

Дата

Тип

Тип

jar
Описание

Описание

when
Simple Pattern Matching
Ссылка на сайт

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

https://github.com/ufukhalis/when
Система контроля версий

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

https://github.com/ufukhalis/when/tree/master

Скачать when

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

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

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
io.projectreactor : reactor-core jar 3.3.3.RELEASE
io.projectreactor : reactor-test jar 3.3.3.RELEASE

test (1)

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

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

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

Build Status Coverage Status

WHEN

WHEN is a simple matching library which only needs Java 8+ version.

How to Use

Firstly, you should add latest WHEN dependency to your project.

<dependency>
    <groupId>io.github.ufukhalis</groupId>
    <artifactId>when</artifactId>
    <version>0.0.6</version>
</dependency>

Then, we can easily build when conditions like below. WHEN won't work until you call the toOptional method.


Optional<Integer> result = When.of(integer)
                .condition(i -> i == 10, i -> i + 1)
                .condition(i -> i == 20, i -> i + 2)
                .toOptional();

If there is no match the optional value will be empty.

You can also pass Optional.


Optional<Integer> result = When.of(Optional.of(10))
                .condition(i -> i == 12, i -> i + 1)
                .condition(i -> i == 11, i -> i + 1)
                .condition(i -> i == 10, i -> i + 1)
                .toOptional();

And also you can use other methods to trigger pipeline such as getOrElse or getOrElseGet.


Integer result = When.of(integer)
                .condition(i -> i == 11, i -> i + 1)
                .condition(i -> i == 12, i -> i + 1)
                .condition(i -> i == 13, i -> i + 1)
                .getOrElseGet(() -> 10);


Integer result = When.of(integer)
                .condition(i -> i == 11, i -> i + 1)
                .condition(i -> i == 12, i -> i + 1)
                .condition(i -> i == 13, i -> i + 1)
                .getOrElse(10);

When project has also reactor Mono type support.


Mono<Integer> result = When.of(Mono.just(10))
                .condition(i -> i == 10, i -> 1)
                .condition(i -> i == 20, i -> 2)
                .execute();

Important Note : If there are multiple match for When, it will return the last match. But it won't execute previous matches.

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENCE.

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

Версия
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1