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

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

import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Function2;
import com.github.tonivade.purefun.Tuple2;
import com.github.tonivade.purefun.generic.HList.HCons;

@FunctionalInterface
public interface HApply {

  R apply(F context, A value);

  static  HApply, A, B> function() {
    return (function, value) -> function.apply(value);
  }

  static  HApply identity() {
    return (context, value) -> value;
  }

  static  HApply, Function1>, Function1> compose() {
    return combine(Function1::andThen);
  }

  static  HApply, C> combine(Function2 combinator) {
    return (context, tuple) -> tuple.applyTo(combinator);
  }

  static > HApply, HCons> cons(Function1 mapper) {
    return (context, tuple) -> tuple.map1(mapper).applyTo(HList::cons);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy