io.github.olib963.javatest.fixtures.internal.Success Maven / Gradle / Ivy
package io.github.olib963.javatest.fixtures.internal;
import io.github.olib963.javatest.fixtures.Try;
import java.util.Objects;
import java.util.function.Function;
public class Success implements Try {
private final A value;
public Success(A value) {
this.value = value;
}
@Override
public Try mapError(Function f) {
return this;
}
@Override
public Try map(Function f) {
return new Success<>(f.apply(value));
}
@Override
public Try flatMap(Function> f) {
return f.apply(value);
}
@Override
public A recoverWith(Function f) {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Success> success = (Success>) o;
return Objects.equals(value, success.value);
}
@Override
public int hashCode() {
return Objects.hash(Success.class, value);
}
@Override
public String toString() {
return "Success(" + value + ')';
}
}