Class IOFunctions
java.lang.Object
fj.data.IOFunctions
IO monad for processing files, with main methods
enumFileLines(File, Option, Iteratee.IterV),
enumFileChars(File, Option, Iteratee.IterV) and enumFileCharChunks(File, Option, Iteratee.IterV)
(the latter one is the fastest as char chunks read from the file are directly passed to the iteratee
without indirection in between).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> IO <B> static <A,B> IO <B> static <A,B> IO <B> static <A,B> IO <B> static <A,B, C> IO <C> static IO<BufferedReader> bufferedReader(File f, Option<Charset> encoding) static <A> F<Reader, F<Iteratee.IterV<char[], A>, IO<Iteratee.IterV<char[], A>>>> A function that feeds an iteratee with character chunks read from aReader(char[] of sizeDEFAULT_BUFFER_SIZE).static <A> F<Reader, F<Iteratee.IterV<Character, A>, IO<Iteratee.IterV<Character, A>>>> A function that feeds an iteratee with characters read from aReader(chars are read in chunks of sizeDEFAULT_BUFFER_SIZE).static <A> IO<Iteratee.IterV<char[], A>> enumFileCharChunks(File f, Option<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<Character, A>> enumFileChars(File f, Option<Charset> encoding, Iteratee.IterV<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<String, A>> enumFileLines(File f, Option<Charset> encoding, Iteratee.IterV<String, A> i) An IO monad that reads lines from the given file (using aBufferedReader) and passes lines to the provided iteratee.fileReader(File f, Option<Charset> encoding) static <A,B> IO <B> static <A> IO<A> static <A> IO<A> fromTry(Try0<A, ? extends IOException> t) static IO<LazyString> interact(F<LazyString, LazyString> f) Read lines from stdin until condition is not met, transforming each line and printing the result to stdout.static <A> IO<A> static <A> IO<A> static <A> IO<A> static <A> SafeIO<A> static <A> SafeIO<A> static <A,B> IO <A> static <A,B, C> IO <C> static <A> F<BufferedReader, F<Iteratee.IterV<String, A>, IO<Iteratee.IterV<String, A>>>> A function that feeds an iteratee with lines read from aBufferedReader.static <A,B> IO <B> static <A> P1<Validation<IOException, A>> static <A> IO<State<BufferedReader, Validation<IOException, String>>> replicateM(IO<A> ioa, int n) static <A> ARun io, rethrowing any IOException wrapped in a RuntimeExceptionEvaluate each action in the sequence from left to right, and collect the results.sequenceWhile(Stream<IO<A>> stream, F<A, Boolean> f) sequenceWhileEager(Stream<IO<A>> stream, F<A, Boolean> f) static <A> SafeIO<A> Convert io to a SafeIO, throwing any IOException wrapped inside a RuntimeExceptionstatic <A> SafeIO<Validation<IOException, A>> toSafeValidation(IO<A> io) static <A> Try0<A, IOException> static <A> IO<A> unit(A a)
-
Field Details
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE- See Also:
-
closeReader
-
ioUnit
-
stdinBufferedReader
-
-
Constructor Details
-
IOFunctions
private IOFunctions()
-
-
Method Details
-
toTry
-
p
-
fromF
-
fromTry
-
toSafe
-
runSafe
Run io, rethrowing any IOException wrapped in a RuntimeException- Parameters:
io-
-
closeReader
-
enumFileLines
public static <A> IO<Iteratee.IterV<String,A>> enumFileLines(File f, Option<Charset> encoding, Iteratee.IterV<String, A> i) An IO monad that reads lines from the given file (using aBufferedReader) and passes lines to the provided iteratee. May not be suitable for files with very long lines, consider to useenumFileCharChunks(File, Option, Iteratee.IterV)orenumFileChars(File, Option, Iteratee.IterV)as an alternative.- Parameters:
f- the file to read, must not benullencoding- the encoding to use,Option.none()means platform defaulti- the iteratee that is fed with lines read from the file
-
enumFileCharChunks
public static <A> IO<Iteratee.IterV<char[],A>> enumFileCharChunks(File f, Option<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 benullencoding- the encoding to use,Option.none()means platform defaulti- the iteratee that is fed with char chunks read from the file
-
enumFileChars
public static <A> IO<Iteratee.IterV<Character, A>> enumFileChars(File f, Option<Charset> encoding, Iteratee.IterV<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 benullencoding- the encoding to use,Option.none()means platform defaulti- the iteratee that is fed with chars read from the file
-
bufferedReader
-
fileReader
-
bracket
-
unit
-
lazy
-
lazy
-
lazySafe
-
lazySafe
-
lineReader
public static <A> F<BufferedReader, F<Iteratee.IterV<String,A>, IO<Iteratee.IterV<String, lineReader()A>>>> A function that feeds an iteratee with lines read from aBufferedReader. -
charChunkReader
public static <A> F<Reader, F<Iteratee.IterV<char[],A>, IO<Iteratee.IterV<char[], charChunkReader()A>>>> A function that feeds an iteratee with character chunks read from aReader(char[] of sizeDEFAULT_BUFFER_SIZE). -
charChunkReader2
public static <A> F<Reader, F<Iteratee.IterV<Character, A>, IO<Iteratee.IterV<Character, A>>>> charChunkReader2()A function that feeds an iteratee with characters read from aReader(chars are read in chunks of sizeDEFAULT_BUFFER_SIZE). -
map
-
as
-
voided
-
bind
-
when
-
unless
-
sequence
-
sequence
-
join
-
toSafeValidation
-
append
-
left
-
flatMap
-
interactWhile
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 conditiontransform- Function to change line value
-
sequenceWhileEager
-
sequenceWhile
-
apply
-
liftM2
-
replicateM
-
readerState
-
stdinReadLine
-
stdoutPrintln
-
stdoutPrint
-
getContents
-
interact
-