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

fj.data.IOW 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.data;

import fj.F;
import fj.Unit;

import java.io.IOException;

/**
 * Created by MarkPerry on 9/06/2015.
 */
public final class IOW implements IO {

    private final 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 SafeIO> safe() {
        return IOFunctions.toSafeValidation(io);
    }

    public  IOW map(F f) { return lift(IOFunctions.map(io, f)); }

    public  IOW bind(F> f) { return lift(IOFunctions.bind(io, f)); }

    public  IOW append(IO iob) { return lift(IOFunctions.append(io, iob)); }

    public static IOW getContents() {
        return lift(() -> IOFunctions.getContents().run());
    }

    public static IOW interact(F f) {
        return lift(() -> IOFunctions.interact(f).run());
    }
}