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

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

import static java.util.Objects.requireNonNull;

import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Higher1;
import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.typeclasses.Functor;

@HigherKind
public final class Coyoneda {
  
  private final Higher1 value;
  private final Function1 map;
  
  private Coyoneda(Higher1 value, Function1 map) {
    this.value = requireNonNull(value);
    this.map = requireNonNull(map);
  }

  public Higher1 run(Functor functor) {
    return functor.map(value, map);
  }
  
  public  Coyoneda map(Function1 next) {
    return new Coyoneda<>(value, map.andThen(next));
  }
  
  public static  Coyoneda of(Higher1 value, Function1 map) {
    return new Coyoneda<>(value, map);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy