public final class IOFunctions
extends java.lang.Object
enumFileLines(java.io.File, fj.data.Option<java.nio.charset.Charset>, fj.data.Iteratee.IterV<java.lang.String, A>)
,
enumFileChars(java.io.File, fj.data.Option<java.nio.charset.Charset>, fj.data.Iteratee.IterV<java.lang.Character, A>)
and enumFileCharChunks(java.io.File, fj.data.Option<java.nio.charset.Charset>, fj.data.Iteratee.IterV<char[], A>)
(the latter one is the fastest as char chunks read from the file are directly passed to the iteratee
without indirection in between).Modifier and Type | Field and Description |
---|---|
static F<java.io.Reader,IO<Unit>> |
closeReader |
static IO<Unit> |
ioUnit |
static java.io.BufferedReader |
stdinBufferedReader |
Modifier and Type | Method and Description |
---|---|
static <A,B> IO<B> |
append(IO<A> io1,
IO<B> io2) |
static <A,B> IO<B> |
apply(IO<A> io,
IO<F<A,B>> iof) |
static <A,B> IO<B> |
as(IO<A> io,
B b) |
static <A,B> IO<B> |
bind(IO<A> io,
F<A,IO<B>> f) |
static <A,B,C> IO<C> |
bracket(IO<A> init,
F<A,IO<B>> fin,
F<A,IO<C>> body) |
static IO<java.io.BufferedReader> |
bufferedReader(java.io.File f,
Option<java.nio.charset.Charset> encoding) |
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 ). |
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 ). |
static IO<Unit> |
closeReader(java.io.Reader r) |
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.
|
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.
|
static <A> IO<Iteratee.IterV<java.lang.String,A>> |
enumFileLines(java.io.File f,
Option<java.nio.charset.Charset> encoding,
Iteratee.IterV<java.lang.String,A> i)
An IO monad that reads lines from the given file (using a
BufferedReader ) and passes
lines to the provided iteratee. |
static IO<java.io.Reader> |
fileReader(java.io.File f,
Option<java.nio.charset.Charset> encoding) |
static <A,B> IO<B> |
flatMap(IO<A> io,
F<A,IO<B>> f) |
static <A> IO<A> |
fromF(F0<A> p) |
static <A> IO<A> |
fromTry(Try0<A,? extends java.io.IOException> t) |
static IO<LazyString> |
getContents() |
static IO<Unit> |
interact(F<LazyString,LazyString> f) |
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.
|
static <A> IO<A> |
join(IO<IO<A>> io1) |
static <A> IO<A> |
lazy(F<Unit,A> f) |
static <A> IO<A> |
lazy(F0<A> p) |
static <A> SafeIO<A> |
lazySafe(F<Unit,A> f) |
static <A> SafeIO<A> |
lazySafe(F0<A> f) |
static <A,B> IO<A> |
left(IO<A> io1,
IO<B> io2) |
static <A,B,C> IO<C> |
liftM2(IO<A> ioa,
IO<B> iob,
F2<A,B,C> f) |
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 . |
static <A,B> IO<B> |
map(IO<A> io,
F<A,B> f) |
static <A> P1<Validation<java.io.IOException,A>> |
p(IO<A> io) |
static <A> IO<State<java.io.BufferedReader,Validation<java.io.IOException,java.lang.String>>> |
readerState() |
static <A> IO<List<A>> |
replicateM(IO<A> ioa,
int n) |
static <A> A |
runSafe(IO<A> io)
Run io, rethrowing any IOException wrapped in a RuntimeException
|
static <A> IO<List<A>> |
sequence(List<IO<A>> list)
Evaluate each action in the sequence from left to right, and collect the results.
|
static <A> IO<Stream<A>> |
sequence(Stream<IO<A>> stream) |
static <A> IO<Stream<A>> |
sequenceWhile(Stream<IO<A>> stream,
F<A,java.lang.Boolean> f) |
static <A> IO<Stream<A>> |
sequenceWhileEager(Stream<IO<A>> stream,
F<A,java.lang.Boolean> f) |
static IO<java.lang.String> |
stdinReadLine() |
static IO<Unit> |
stdoutPrint(java.lang.String s) |
static IO<Unit> |
stdoutPrintln(java.lang.String s) |
static <A> SafeIO<A> |
toSafe(IO<A> io)
Convert io to a SafeIO, throwing any IOException wrapped inside a RuntimeException
|
static <A> SafeIO<Validation<java.io.IOException,A>> |
toSafeValidation(IO<A> io) |
static <A> Try0<A,java.io.IOException> |
toTry(IO<A> io) |
static <A> IO<A> |
unit(A a) |
static IO<Unit> |
unless(java.lang.Boolean b,
IO<Unit> io) |
static <A> IO<Unit> |
voided(IO<A> io) |
static IO<Unit> |
when(java.lang.Boolean b,
IO<Unit> io) |
public static <A> P1<Validation<java.io.IOException,A>> p(IO<A> io)
public static <A> SafeIO<A> toSafe(IO<A> io)
io
- public static <A> A runSafe(IO<A> io)
io
- public static <A> IO<Iteratee.IterV<java.lang.String,A>> enumFileLines(java.io.File f, Option<java.nio.charset.Charset> encoding, Iteratee.IterV<java.lang.String,A> i)
BufferedReader
) and passes
lines to the provided iteratee. May not be suitable for files with very long
lines, consider to use enumFileCharChunks(java.io.File, fj.data.Option<java.nio.charset.Charset>, fj.data.Iteratee.IterV<char[], A>)
or enumFileChars(java.io.File, fj.data.Option<java.nio.charset.Charset>, fj.data.Iteratee.IterV<java.lang.Character, A>)
as an alternative.f
- the file to read, must not be null
encoding
- the encoding to use, Option.none()
means platform defaulti
- the iteratee that is fed with lines read from the filepublic static <A> IO<Iteratee.IterV<char[],A>> enumFileCharChunks(java.io.File f, Option<java.nio.charset.Charset> encoding, Iteratee.IterV<char[],A> i)
f
- the file to read, must not be null
encoding
- the encoding to use, Option.none()
means platform defaulti
- the iteratee that is fed with char chunks read from the filepublic 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)
f
- the file to read, must not be null
encoding
- the encoding to use, Option.none()
means platform defaulti
- the iteratee that is fed with chars read from the filepublic static IO<java.io.BufferedReader> bufferedReader(java.io.File f, Option<java.nio.charset.Charset> encoding)
public static IO<java.io.Reader> fileReader(java.io.File f, Option<java.nio.charset.Charset> encoding)
public static <A> IO<A> unit(A a)
public static <A> F<java.io.BufferedReader,F<Iteratee.IterV<java.lang.String,A>,IO<Iteratee.IterV<java.lang.String,A>>>> lineReader()
BufferedReader
.public static <A> F<java.io.Reader,F<Iteratee.IterV<char[],A>,IO<Iteratee.IterV<char[],A>>>> charChunkReader()
Reader
(char[] of size DEFAULT_BUFFER_SIZE
).public static <A> F<java.io.Reader,F<Iteratee.IterV<java.lang.Character,A>,IO<Iteratee.IterV<java.lang.Character,A>>>> charChunkReader2()
Reader
(chars are read in chunks of size DEFAULT_BUFFER_SIZE
).public static <A> IO<List<A>> sequence(List<IO<A>> list)
public static <A> SafeIO<Validation<java.io.IOException,A>> toSafeValidation(IO<A> io)
public static IO<Unit> interactWhile(F<java.lang.String,java.lang.Boolean> condition, F<java.lang.String,java.lang.String> transform)
condition
- Read lines until a line does not satisfy conditiontransform
- Function to change line valuepublic static <A> IO<Stream<A>> sequenceWhileEager(Stream<IO<A>> stream, F<A,java.lang.Boolean> f)
public static <A> IO<Stream<A>> sequenceWhile(Stream<IO<A>> stream, F<A,java.lang.Boolean> f)
public static <A> IO<State<java.io.BufferedReader,Validation<java.io.IOException,java.lang.String>>> readerState()
public static IO<java.lang.String> stdinReadLine()
public static IO<LazyString> getContents()
public static IO<Unit> interact(F<LazyString,LazyString> f)