com.github.tonivade.purefun.PartialFunction2 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 com.github.tonivade.purefun.type.Option;
public interface PartialFunction2 {
R apply(A a, B b);
boolean isDefinedAt(A a, B b);
default Function2> lift() {
return (a, b) -> isDefinedAt(a, b) ? Option.some(apply(a, b)) : Option.none();
}
static PartialFunction2 of(Matcher2 isDefined, Function2 apply) {
return new PartialFunction2() {
@Override
public boolean isDefinedAt(A a, B b) {
return isDefined.match(a, b);
}
@Override
public R apply(A a, B b) {
return apply.apply(a, b);
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy