All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tonivade.purefun.PartialFunction3 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;

import com.github.tonivade.purefun.type.Option;

public interface PartialFunction3 {

  R apply(A a, B b, C c);

  boolean isDefinedAt(A a, B b, C c);

  default Function3> lift() {
    return (a, b, c) -> isDefinedAt(a, b, c) ? Option.some(apply(a, b, c)) : Option.none();
  }

  static  PartialFunction3 of(Matcher3 matcher, PartialFunction3 apply) {
    return new PartialFunction3() {

      @Override
      public boolean isDefinedAt(A a, B b, C c) {
        return matcher.match(a, b, c);
      }

      @Override
      public R apply(A a, B b, C c) {
        return apply.apply(a, b, c);
      }
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy