![JAR search and dependency download from the Maven repository](/logo.png)
fj.data.Reader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
package fj.data;
import fj.F;
import fj.F1Functions;
/**
* The Reader monad (also called the function monad, so equivalent to the idea of F).
* Created by MarkPerry on 7/07/2014.
*/
public class Reader {
private F function;
public Reader(F f) {
function = f;
}
public F getFunction() {
return function;
}
public static Reader unit(F f) {
return new Reader(f);
}
public static Reader constant(B b) {
return unit(a -> b);
}
public B f(A a) {
return function.f(a);
}
public Reader map(F f) {
return unit(F1Functions.andThen(function, f));
}
public Reader andThen(F f) {
return map(f);
}
public Reader flatMap(F> f) {
return unit(a -> f.f(function.f(a)).f(a));
}
public Reader bind(F> f) {
return flatMap(f);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy