com.github.tonivade.purefun.With Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun;
import static java.util.Objects.requireNonNull;
import java.util.Objects;
public final class With {
private static final Equal> EQUAL = Equal.>of().comparing(With::get);
private final A value;
private With(A value) {
this.value = requireNonNull(value);
}
public A get() {
return value;
}
public void end(Consumer1 consumer) {
consumer.accept(value);
}
public With then(Function1 function) {
return with(function.apply(value));
}
public With then(Function2 function, B b) {
return with(function.apply(value, b));
}
public With then(Function3 function, B b, C c) {
return with(function.apply(value, b, c));
}
public With then(Function4 function, B b, C c, D d) {
return with(function.apply(value, b, c, d));
}
public With then(Function5 function, B b, C c, D d, E e) {
return with(function.apply(value, b, c, d, e));
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public boolean equals(Object obj) {
return EQUAL.applyTo(this, obj);
}
public static With with(T value) {
return new With<>(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy