Package fj.data

Class IOFunctions

    • Field Detail

      • closeReader

        public static final F<java.io.Reader,​IO<Unit>> closeReader
      • ioUnit

        public static final IO<Unit> ioUnit
      • stdinBufferedReader

        public static final java.io.BufferedReader stdinBufferedReader
    • Constructor Detail

      • IOFunctions

        private IOFunctions()
    • Method Detail

      • toTry

        public static <A> Try0<A,​java.io.IOException> toTry​(IO<A> io)
      • p

        public static <A> P1<Validation<java.io.IOException,​A>> p​(IO<A> io)
      • fromF

        public static <A> IO<A> fromF​(F0<A> p)
      • fromTry

        public static <A> IO<A> fromTry​(Try0<A,​? extends java.io.IOException> t)
      • toSafe

        public static <A> SafeIO<A> toSafe​(IO<A> io)
        Convert io to a SafeIO, throwing any IOException wrapped inside a RuntimeException
        Parameters:
        io -
      • runSafe

        public static <A> A runSafe​(IO<A> io)
        Run io, rethrowing any IOException wrapped in a RuntimeException
        Parameters:
        io -
      • closeReader

        public static IO<Unit> closeReader​(java.io.Reader r)
      • enumFileCharChunks

        public static <A> IO<Iteratee.IterV<char[],​A>> enumFileCharChunks​(java.io.File f,
                                                                                Option<java.nio.charset.Charset> encoding,
                                                                                Iteratee.IterV<char[],​A> i)
        An IO monad that reads char chunks from the given file and passes them to the given iteratee.
        Parameters:
        f - the file to read, must not be null
        encoding - the encoding to use, Option.none() means platform default
        i - the iteratee that is fed with char chunks read from the file
      • enumFileChars

        public static <A> IO<Iteratee.IterV<java.lang.Character,​A>> enumFileChars​(java.io.File f,
                                                                                        Option<java.nio.charset.Charset> encoding,
                                                                                        Iteratee.IterV<java.lang.Character,​A> i)
        An IO monad that reads char chunks from the given file and passes single chars to the given iteratee.
        Parameters:
        f - the file to read, must not be null
        encoding - the encoding to use, Option.none() means platform default
        i - the iteratee that is fed with chars read from the file
      • bufferedReader

        public static IO<java.io.BufferedReader> bufferedReader​(java.io.File f,
                                                                Option<java.nio.charset.Charset> encoding)
      • fileReader

        public static IO<java.io.Reader> fileReader​(java.io.File f,
                                                    Option<java.nio.charset.Charset> encoding)
      • bracket

        public static <A,​B,​C> IO<C> bracket​(IO<A> init,
                                                        F<A,​IO<B>> fin,
                                                        F<A,​IO<C>> body)
      • unit

        public static <A> IO<A> unit​(A a)
      • lazy

        public static <A> IO<A> lazy​(F0<A> p)
      • lazy

        public static <A> IO<A> lazy​(F<Unit,​A> f)
      • lazySafe

        public static <A> SafeIO<A> lazySafe​(F<Unit,​A> f)
      • lazySafe

        public static <A> SafeIO<A> lazySafe​(F0<A> f)
      • lineReader

        public static <A> F<java.io.BufferedReader,​F<Iteratee.IterV<java.lang.String,​A>,​IO<Iteratee.IterV<java.lang.String,​A>>>> lineReader()
        A function that feeds an iteratee with lines read from a BufferedReader.
      • charChunkReader

        public static <A> F<java.io.Reader,​F<Iteratee.IterV<char[],​A>,​IO<Iteratee.IterV<char[],​A>>>> charChunkReader()
        A function that feeds an iteratee with character chunks read from a Reader (char[] of size DEFAULT_BUFFER_SIZE).
      • charChunkReader2

        public static <A> F<java.io.Reader,​F<Iteratee.IterV<java.lang.Character,​A>,​IO<Iteratee.IterV<java.lang.Character,​A>>>> charChunkReader2()
        A function that feeds an iteratee with characters read from a Reader (chars are read in chunks of size DEFAULT_BUFFER_SIZE).
      • map

        public static <A,​B> IO<B> map​(IO<A> io,
                                            F<A,​B> f)
      • as

        public static <A,​B> IO<B> as​(IO<A> io,
                                           B b)
      • voided

        public static <A> IO<Unit> voided​(IO<A> io)
      • bind

        public static <A,​B> IO<B> bind​(IO<A> io,
                                             F<A,​IO<B>> f)
      • when

        public static IO<Unit> when​(java.lang.Boolean b,
                                    IO<Unit> io)
      • unless

        public static IO<Unit> unless​(java.lang.Boolean b,
                                      IO<Unit> io)
      • sequence

        public static <A> IO<List<A>> sequence​(List<IO<A>> list)
        Evaluate each action in the sequence from left to right, and collect the results.
      • sequence

        public static <A> IO<Stream<A>> sequence​(Stream<IO<A>> stream)
      • join

        public static <A> IO<A> join​(IO<IO<A>> io1)
      • toSafeValidation

        public static <A> SafeIO<Validation<java.io.IOException,​A>> toSafeValidation​(IO<A> io)
      • append

        public static <A,​B> IO<B> append​(IO<A> io1,
                                               IO<B> io2)
      • left

        public static <A,​B> IO<A> left​(IO<A> io1,
                                             IO<B> io2)
      • flatMap

        public static <A,​B> IO<B> flatMap​(IO<A> io,
                                                F<A,​IO<B>> f)
      • interactWhile

        public static IO<Unit> interactWhile​(F<java.lang.String,​java.lang.Boolean> condition,
                                             F<java.lang.String,​java.lang.String> transform)
        Read lines from stdin until condition is not met, transforming each line and printing the result to stdout.
        Parameters:
        condition - Read lines until a line does not satisfy condition
        transform - Function to change line value
      • sequenceWhileEager

        public static <A> IO<Stream<A>> sequenceWhileEager​(Stream<IO<A>> stream,
                                                           F<A,​java.lang.Boolean> f)
      • sequenceWhile

        public static <A> IO<Stream<A>> sequenceWhile​(Stream<IO<A>> stream,
                                                      F<A,​java.lang.Boolean> f)
      • apply

        public static <A,​B> IO<B> apply​(IO<A> io,
                                              IO<F<A,​B>> iof)
      • liftM2

        public static <A,​B,​C> IO<C> liftM2​(IO<A> ioa,
                                                       IO<B> iob,
                                                       F2<A,​B,​C> f)
      • replicateM

        public static <A> IO<List<A>> replicateM​(IO<A> ioa,
                                                 int n)
      • readerState

        public static <A> IO<State<java.io.BufferedReader,​Validation<java.io.IOException,​java.lang.String>>> readerState()
      • stdinReadLine

        public static IO<java.lang.String> stdinReadLine()
      • stdoutPrintln

        public static IO<Unit> stdoutPrintln​(java.lang.String s)
      • stdoutPrint

        public static IO<Unit> stdoutPrint​(java.lang.String s)