fj.data.IOW 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.Unit;
import java.io.IOException;
/**
* Created by MarkPerry on 9/06/2015.
*/
public class IOW implements IO {
private IO io;
private IOW(IO in) {
io = in;
}
public static IOW lift(IO io) {
return new IOW<>(io);
}
@Override
public A run() throws IOException {
return io.run();
}
public IOW map(F f) {
return lift(() -> f.f(io.run()));
}
public IOW bind(F> f) throws IOException {
return lift(f.f(io.run()));
}
public IOW append(IO iob) {
return lift(() -> {
io.run();
return iob.run();
});
}
public IOW getContents() {
return lift(() -> IOFunctions.getContents().run());
}
public IOW interact(F f) {
return IOW.lift(() -> IOFunctions.interact(f).run());
}
}