TypeAlias, Result, Maybe and others for Java
Find a file
2018-03-02 23:32:07 +00:00
.mvn/wrapper mvn: upgrade wrapper to maven 3.5.2 2018-03-01 18:23:02 +00:00
.travis-support@b8593e541b Add travis-support submodule 2017-09-17 10:07:53 +01:00
src Add test for normal Mon.factory() behaviour 2018-03-02 23:32:07 +00:00
.gitignore Functor<T> 2017-09-16 22:34:44 +01:00
.gitmodules Add travis-support submodule 2017-09-17 10:07:53 +01:00
.travis.yml .travis.yml: clean up unused env.global 2017-10-19 22:47:45 +01:00
CHANGELOG CHANGELOG 2018-02-28 22:27:11 +00:00
codesigning.asc.enc codesigning.asc.enc: added 2017-09-17 10:12:39 +01:00
Jenkinsfile.groovy jenkins: disable java 9 build until maven-failsafe-plugin 2.21 2018-03-01 20:11:05 +00:00
LICENSE.txt Functor<T> 2017-09-16 22:34:44 +01:00
lombok.config lombok.config: added to prevent generated annotation 2018-02-28 22:37:02 +00:00
mvnw mvnw*: make executable 2017-09-17 10:31:35 +01:00
mvnw.cmd mvnw*: make executable 2017-09-17 10:31:35 +01:00
pom.xml Upgrade maven-{surefire,failsafe}-plugins to 2.20.1 to compile with java 9 2018-02-28 22:09:38 +00:00
README.md version set to 0.4.0 2017-12-10 17:02:11 +00:00

Mon

TypeAlias for Java

GitHub release Codacy Badge Build Status Coverage Status codecov

Maven

<dependency>
    <groupId>net.kemitix</groupId>
    <artifactId>mon</artifactId>
    <version>0.4.0</version>
</dependency>

Usage

TypeAlias

class Goal extends TypeAlias<String> {
    private Goal(final String goal) {
        super(goal);
    }
    public static Goal of(final String goal) {
        return new Goal(goal);
    }
}
Goal goal = Goal.of("goal");

void foo(final Goal goal) {
    System.out.println("The goal is " + goal.getValue());
}

Maybe (Just & Nothing)

assertThat(Maybe.maybe(null)).isEqualTo(Maybe.nothing());
assertThat(Maybe.maybe(1)).isEqualTo(Maybe.just(1));
assertThat(Maybe.nothing()
                .orElseGet(() -> 1)).isEqualTo(1);
assertThat(Maybe.just(1)
                .orElseGet(() -> 2)).isEqualTo(1);
assertThat(Maybe.nothing()
                .orElse(1)).isEqualTo(1);
assertThat(Maybe.just(1)
                .orElse(2)).isEqualTo(1);
assertThat(Maybe.just(1)
                .filter(v -> v > 2)).isEqualTo(Maybe.nothing());
assertThat(Maybe.just(3)
                .filter(v -> v > 2)).isEqualTo(Maybe.just(3));
assertThat(Maybe.just(1)
                .toOptional()).isEqualTo(Optional.of(1));
assertThat(Maybe.nothing()
                .toOptional()).isEqualTo(Optional.empty());
assertThat(Maybe.fromOptional(Optional.of(1))).isEqualTo(Maybe.just(1));
assertThat(Maybe.fromOptional(Optional.empty())).isEqualTo(Maybe.nothing());
final AtomicInteger reference = new AtomicInteger(0);
assertThat(Maybe.just(1).peek(reference::set)).isEqualTo(Maybe.just(1));
assertThat(reference).hasValue(1);
assertThat(Maybe.nothing().peek(v -> reference.incrementAndGet())).isEqualTo(Maybe.nothing());
assertThat(reference).hasValue(1);
assertThatCode(() -> Maybe.just(1).orElseThrow(IllegalStateException::new))
        .doesNotThrowAnyException();
assertThatThrownBy(() -> Maybe.nothing().orElseThrow(IllegalStateException::new))
        .isInstanceOf(IllegalStateException.class);