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

fj.Effect Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 5.0
Show newest version
package fj;

import fj.function.Effect0;
import fj.function.Effect1;
import fj.function.Effect2;
import fj.function.Effect3;
import fj.function.Effect4;
import fj.function.Effect5;
import fj.function.Effect6;
import fj.function.Effect7;
import fj.function.Effect8;

import static fj.Unit.unit;

/**
 * Represents a side-effect.
 *
 * @version %build.number%
 */
public final class Effect {

	private Effect() {}

    public static P1 f(Effect0 e) {
      return P.lazy(() -> {
        e.f();
        return unit();
      });
    }

    /**
   * Returns a function for the given effect.
   *
   * @return The function using the given effect.
   */
  public static  F f(Effect1 e1) {
    return a -> {
        e1.f(a);
        return unit();
    };
  }

    public static  F2 f(Effect2 e) {
        return (a, b) -> {
            e.f(a, b);
            return unit();
        };
    }

    public static  F3 f(Effect3 e) {
        return (a, b, c) -> {
            e.f(a, b, c);
            return unit();
        };
    }

    public static  F4 f(Effect4 e) {
        return (a, b, c, d) -> {
            e.f(a, b, c, d);
            return unit();
        };
    }

    public static  F5 f(Effect5 z) {
        return (a, b, c, d, e) -> {
            z.f(a, b, c, d, e);
            return unit();
        };
    }

    public static  F6 f(Effect6 z) {
        return (a, b, c, d, e, f) -> {
            z.f(a, b, c, d, e, f);
            return unit();
        };
    }

    public static  F7 f(Effect7 z) {
        return (a, b, c, d, e, f, g) -> {
            z.f(a, b, c, d, e, f, g);
            return unit();
        };
    }

    public static  F8 f(Effect8 z) {
        return (a, b, c, d, e, f, g, h) -> {
            z.f(a, b, c, d, e, f, g, h);
            return unit();
        };
    }

    /**
   * A contra-variant functor on effect.
   *
   * @param f The function to map over the effect.
   * @return An effect after a contra-variant map.
   */
  public static  Effect1 contramap(Effect1 e1, final F f) {
    return b -> e1.f(f.f(b));
  }
  
  public static  Effect1 lazy(final F f) {
    return f::f;

  }

//	public static  void f(Effect1 )

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy