IOTable

com.phasmidsoftware.tableparser.cats.table.IOTable
object IOTable

The methods here are basically copies of the same methods in Table, but resulting in IO rather than Try.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
IOTable.type

Members list

Value members

Concrete methods

def apply[X](xs: Iterable[X], maybeHeader: Option[Header]): Table[X]

Method to construct one of the standard table types, given an Iterable of T and an optional header.

Method to construct one of the standard table types, given an Iterable of T and an optional header.

Type parameters

X

the underlying type of xs.

Value parameters

maybeHeader

an optional Header.

xs

an Iterable of X.

Attributes

Returns

a Table[X] which is either a HeadedTable or an UnheadedTable, as appropriate.

def csvLines[X](using renderer: CsvRenderer[X], generator: CsvGenerator[X]): Stream[IO, X] => Stream[IO, String]

A Pipe which renders rows as the lines of a CSV file: the header first, then one line for each row (without line endings: see writeCSVFile).

A Pipe which renders rows as the lines of a CSV file: the header first, then one line for each row (without line endings: see writeCSVFile).

Type parameters

X

the row type.

Value parameters

generator

implicit CsvGenerator[X] (for the header).

renderer

implicit CsvRenderer[X].

Attributes

Returns

a Pipe[IO, X, String].

def parse[T : TableParser](ws: Iterator[String], n: Int): IO[T]

Primary method to parse a table from an Iterator of String. This method is, in turn, invoked by all other parse methods defined below (other than parseSequence).

Primary method to parse a table from an Iterator of String. This method is, in turn, invoked by all other parse methods defined below (other than parseSequence).

Type parameters

T

the type of the resulting table.

Value parameters

ws

the Strings.

Attributes

Returns

an IO[T]

def parse[T : TableParser](ws: Iterator[String]): IO[T]

Method to parse a table from an Iterator of String, reading as many header rows as the TableParser expects.

Method to parse a table from an Iterator of String, reading as many header rows as the TableParser expects.

Type parameters

T

the type of the resulting table.

Value parameters

ws

the Strings.

Attributes

Returns

an IO[T]

def parse[T : TableParser](ws: Iterable[String]): IO[T]

Method to parse a table from an Iterable of String.

Method to parse a table from an Iterable of String.

Type parameters

T

the type of the resulting table.

Value parameters

ws

the Strings.

Attributes

Returns

an IO[T]

def parse[T : TableParser](si: => IO[Source]): IO[T]

Method to parse a table from a Source (with proper resource management of the source).

Method to parse a table from a Source (with proper resource management of the source).

Type parameters

T

the type of the resulting table.

Value parameters

si

the Source.

Attributes

Returns

an IO[T]

def parse[T](u: => URI)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from a URI with an implicit encoding.

Method to parse a table from a URI with an implicit encoding.

Type parameters

T

the type of the resulting table.

Value parameters

codec

(implicit) the encoding.

u

the URI.

Attributes

Returns

an IO[T]

def parse[T : TableParser](u: => URI, enc: String): IO[T]

Method to parse a table from a URI with an explicit encoding.

Method to parse a table from a URI with an explicit encoding.

Type parameters

T

the type of the resulting table.

Value parameters

enc

the encoding.

u

the URI.

Attributes

Returns

an IO[T]

def parseFile[T : TableParser](f: => File, enc: String): IO[T]

Method to parse a table from a File.

Method to parse a table from a File.

NOTE: you should use parseFile(String) if you have a pathname in String form.

TESTME

Type parameters

T

the type of the resulting table.

Value parameters

enc

the explicit encoding.

f

the File (call by name in case there is an exception thrown while constructing the file).

Attributes

Returns

an IO[T]

def parseFile[T](f: => File)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from an File.

Method to parse a table from an File.

NOTE: you should use parseFile(String) if you have a pathname in String form.

TESTME

Type parameters

T

the type of the resulting table.

Value parameters

codec

(implicit) the encoding.

f

the File (call by name in case there is an exception thrown while constructing the file).

Attributes

Returns

an IO[T]

def parseFile[T : TableParser](pathname: String, enc: String): IO[T]

Method to parse a table from a File.

Method to parse a table from a File.

Type parameters

T

the type of the resulting table.

Value parameters

enc

the explicit encoding.

pathname

the file pathname.

Attributes

Returns

an IO[T]

def parseFile[T](pathname: String)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from an File.

Method to parse a table from an File.

Type parameters

T

the type of the resulting table.

Value parameters

codec

(implicit) the encoding.

pathname

the file pathname.

Attributes

Returns

a IO[T]

def parseFileRaw(f: File, predicate: Try[RawRow] => Boolean, maybeFixedHeader: Option[Header] = ..., forgiving: Boolean = ...)(using codec: Codec): IO[Table[RawRow]]

Method to parse a table from a File as a table of Seq[String].

Method to parse a table from a File as a table of Seq[String].

Value parameters

codec

(implicit) the encoding.

f

the file.

forgiving

forcing (defaults to true). If true (the default) then an individual malformed row will not prevent subsequent rows being parsed.

maybeFixedHeader

an optional fixed header. If None (the default), we expect to find the header defined in the first line of the file.

Attributes

Returns

an IO of Table[RawRow] where RawRow is a Seq[String].

def parseFileRaw(pathname: String, predicate: Try[RawRow] => Boolean)(using codec: Codec): IO[Table[RawRow]]

Method to parse a table from a File as a table of Seq[String].

Method to parse a table from a File as a table of Seq[String].

Value parameters

codec

(implicit) the encoding.

pathname

the path name.

Attributes

Returns

an IO of Table[RawRow] where RawRow is a Seq[String].

def parseInputStream[T](i: => InputStream)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from an InputStream with an implicit encoding.

Method to parse a table from an InputStream with an implicit encoding.

Type parameters

T

the type of the resulting table.

Value parameters

codec

(implicit) the encoding.

i

the InputStream (call-by-name).

Attributes

Returns

an IO[T]

def parseInputStream[T : TableParser](si: IO[InputStream], enc: String): IO[T]

Method to parse a table from an InputStream with an explicit encoding.

Method to parse a table from an InputStream with an explicit encoding.

Type parameters

T

the type of the resulting table.

Value parameters

enc

the encoding.

si

the InputStream, wrapped in IO.

Attributes

Returns

an IO[T]

def parseRaw(ws: Iterable[String], predicate: Try[RawRow] => Boolean = ..., maybeFixedHeader: Option[Header] = ..., forgiving: Boolean = ..., multiline: Boolean = ...): IO[RawTable]

Method to parse a table of raw rows from an Iterable of String.

Method to parse a table of raw rows from an Iterable of String.

Value parameters

ws

the Strings.

Attributes

Returns

an IO of Table of RawRow

def parseResource[T](w: String, clazz: Class[_] = ...)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from an File.

Method to parse a table from an File.

Type parameters

T

the type of the resulting table.

Value parameters

clazz

the class for which the resource should be sought (should default to the calling class but doesn't).

codec

(implicit) the encoding.

w

the resource name.

Attributes

Returns

an IO[T]

def parseResource[T](u: => URL)(using evidence$1: TableParser[T], codec: Codec): IO[T]

Method to parse a table from a URL.

Method to parse a table from a URL.

Type parameters

T

the type of the resulting table.

Value parameters

u

the URI.

Attributes

Returns

an IO[T]

def parseResource[T : TableParser](u: => URL, enc: String): IO[T]

Method to parse a table from a URL with an explicit encoding.

Method to parse a table from a URL with an explicit encoding.

NOTE: the logic here is different from that of parseResource(u:=>URL)(using codec: Codec) above.

Type parameters

T

the type of the resulting table.

Value parameters

enc

the encoding.

u

the URL.

Attributes

Returns

an IO[T]

def parseResourceRaw(s: String, predicate: Try[RawRow] => Boolean = ..., maybeFixedHeader: Option[Header] = ..., forgiving: Boolean = ..., clazz: Class[_] = ...)(using codec: Codec): IO[Table[RawRow]]

Method to parse a table from a resource as a table of Seq[String].

Method to parse a table from a resource as a table of Seq[String].

Value parameters

clazz

the class for which the resource should be sought (defaults to the calling class).

codec

(implicit) the encoding.

forgiving

forcing (defaults to true). If true (the default) then an individual malformed row will not prevent subsequent rows being parsed.

maybeFixedHeader

an optional fixed header. If None (the default), we expect to find the header defined in the first line of the file.

s

the resource name.

Attributes

Returns

an IO of Table[RawRow] where RawRow is a Seq[String].

def parseSequence[T : TableParser](wss: Iterator[Seq[String]]): IO[T]

Method to parse a table from a sequence of sequences of String (one per row, already split into cells).

Method to parse a table from a sequence of sequences of String (one per row, already split into cells).

Type parameters

T

the type of the resulting table.

Value parameters

wss

the rows, each a sequence of Strings.

Attributes

Returns

an IO[T]

def parseSource[T : TableParser](x: => Source): IO[T]

Method to parse a table from a Source.

Method to parse a table from a Source.

NOTE: the caller is responsible for closing the given Source.

Type parameters

T

the type of the resulting table.

Value parameters

x

the Source.

Attributes

Returns

an IO[T]

def stream(parser: StringTableParser[_])(source: => Source): Stream[IO, parser.Row]

Method to stream the rows of a table, as they are read: the whole table is never in memory. The source is opened when the stream is run, and closed when it ends (whether it completes, fails or is cancelled). The header is read first (as parser reads it); then each row is parsed as it is pulled. The parser's predicate selects the rows; if the parser is forgiving, a row which can't be parsed is logged and left out, otherwise the stream fails with its exception.

Method to stream the rows of a table, as they are read: the whole table is never in memory. The source is opened when the stream is run, and closed when it ends (whether it completes, fails or is cancelled). The header is read first (as parser reads it); then each row is parsed as it is pulled. The parser's predicate selects the rows; if the parser is forgiving, a row which can't be parsed is logged and left out, otherwise the stream fails with its exception.

The parser is passed as a value (not a given) so that the type of its rows is known: for example, IOTable.stream(MovieTableParser)(source) is a Stream[IO, Movie].

Value parameters

parser

a StringTableParser (e.g. a HeadedCSVTableParser, or a RawTableParser).

source

the Source (call-by-name: it is made when the stream is run).

Attributes

Returns

a Stream[IO, parser.Row].

def streamFile(parser: StringTableParser[_])(path: Path)(using codec: Codec): Stream[IO, parser.Row]

Method to stream the rows of a file (see stream).

Method to stream the rows of a file (see stream).

Value parameters

codec

(implicit) the encoding.

parser

a StringTableParser.

path

the path of the file.

Attributes

Returns

a Stream[IO, parser.Row].

def streamLines(parser: StringTableParser[_])(ws: Iterable[String]): Stream[IO, parser.Row]

Method to stream the rows of some lines (see stream).

Method to stream the rows of some lines (see stream).

Value parameters

parser

a StringTableParser.

ws

the lines.

Attributes

Returns

a Stream[IO, parser.Row].

def streamResource(parser: StringTableParser[_])(w: String, clazz: Class[_] = ...)(using codec: Codec): Stream[IO, parser.Row]

Method to stream the rows of a resource (see stream).

Method to stream the rows of a resource (see stream).

Value parameters

clazz

the class relative to which the resource is found.

codec

(implicit) the encoding.

parser

a StringTableParser.

w

the name of the resource.

Attributes

Returns

a Stream[IO, parser.Row].

def streamURI(parser: StringTableParser[_])(uri: URI)(using codec: Codec): Stream[IO, parser.Row]

Method to stream the rows of a URI (see stream). If the URI has a fragment identifier which selects rows (RFC 7111, e.g. "data.csv#row=5-7": see CsvFragment), only those rows are streamed, and the input is read no further than the last row which could be selected.

Method to stream the rows of a URI (see stream). If the URI has a fragment identifier which selects rows (RFC 7111, e.g. "data.csv#row=5-7": see CsvFragment), only those rows are streamed, and the input is read no further than the last row which could be selected.

Value parameters

codec

(implicit) the encoding.

parser

a StringTableParser.

uri

the URI.

Attributes

Returns

a Stream[IO, parser.Row].

def toCSV[T](t: Table[T])(using evidence$1: CsvRenderer[T], evidence$2: CsvGenerator[T], csvAttributes: CsvAttributes): IO[String]

Method to render this Table[T] as a CSV String with (maybe) header.

Method to render this Table[T] as a CSV String with (maybe) header.

Value parameters

csvAttributes

implicit value of CsvAttributes.

generator

implicit value of CsvProductGenerator[Row].

renderer

implicit value of CsvRenderer[Row].

Attributes

Returns

a String.

def toCSVRow(t: Table[Row])(using csvAttributes: CsvAttributes): IO[String]

Method to render the given Table[Row] as a CSV String with header.

Method to render the given Table[Row] as a CSV String with header.

Value parameters

csvAttributes

implicit value of CsvAttributes.

t

the Table[Row] to be rendered.

Attributes

Returns

an Iterable[String]

def writeCSVFile[X](path: Path)(using renderer: CsvRenderer[X], generator: CsvGenerator[X], csvAttributes: CsvAttributes): Stream[IO, X] => Stream[IO, Nothing]

A Pipe which writes rows to a CSV file, as they come: the header first, then one line for each row, each line ending with the CsvAttributes newline. The file is closed when the stream ends.

A Pipe which writes rows to a CSV file, as they come: the header first, then one line for each row, each line ending with the CsvAttributes newline. The file is closed when the stream ends.

Type parameters

X

the row type.

Value parameters

csvAttributes

implicit CsvAttributes.

generator

implicit CsvGenerator[X] (for the header).

path

the path of the file.

renderer

implicit CsvRenderer[X].

Attributes

Returns

a Pipe[IO, X, Nothing].

def writeCSVFileIO(table: Table[Row])(file: File)(using renderer: CsvRenderer[Row], generator: CsvGenerator[Row], csvAttributes: CsvAttributes): IO[FileWriter]

Method to render this Table[T] as a CSV file with (maybe) header.

Method to render this Table[T] as a CSV file with (maybe) header.

Value parameters

csvAttributes

implicit value of CsvAttributes.

file

instance of File where the output should be stored.

generator

implicit value of CsvProductGenerator[Row].

renderer

implicit value of CsvRenderer[Row].

Attributes

def writeCSVFileRow(t: Table[Row], file: File)(using csvAttributes: CsvAttributes): IO[FileWriter]

Method to render the given Table[Row] as a CSV String with header.

Method to render the given Table[Row] as a CSV String with header.

Value parameters

csvAttributes

implicit value of CsvAttributes.

file

the destination File for the rendering of t.

t

the Table[Row] to be rendered.

Attributes

Returns

an Iterable[String]