com.github.tonivade.purefun.CheckedMatcher Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2019, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun;
@FunctionalInterface
public interface CheckedMatcher extends Recoverable {
boolean match(A target) throws Throwable;
default Matcher1 unchecked() {
return recover(this::sneakyThrow);
}
default Matcher1 recover(Function1 mapper) {
return target -> {
try {
return match(target);
} catch (Throwable e) {
return mapper.apply(e);
}
};
}
default CheckedMatcher and(CheckedMatcher other) {
return request -> match(request) && other.match(request);
}
default CheckedMatcher or(CheckedMatcher other) {
return request -> match(request) || other.match(request);
}
default CheckedMatcher negate() {
return request -> !match(request);
}
static CheckedMatcher not(CheckedMatcher matcher) {
return matcher.negate();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy