tysv

Types

pub opaque type Builder(a)

Values

pub fn build(f: fn(a) -> b) -> Builder(fn(a) -> b)
pub fn col(
  builder: Builder(fn(a) -> b),
  parse: fn(String) -> Result(a, Nil),
) -> Builder(b)
pub fn col_sep(
  builder: Builder(a),
  col_sep: String,
) -> Builder(a)

Set column separator.

pub fn from_fs(
  builder: Builder(a),
  fs: file_stream.FileStream,
) -> yielder.Yielder(a)
pub fn from_fs_with_rest(
  builder: Builder(a),
  fs: file_stream.FileStream,
) -> yielder.Yielder(#(a, List(String)))
pub fn from_text(
  builder: Builder(a),
  text: String,
) -> yielder.Yielder(a)
pub fn from_text_with_rest(
  builder: Builder(a),
  text: String,
) -> yielder.Yielder(#(a, List(String)))
pub fn multi_col(
  builder: Builder(fn(a) -> b),
  count: Int,
  parse: fn(List(String)) -> Result(a, Nil),
) -> Builder(b)

Parse list of values from a given number of columns.

const landmarks = "# Landmark,x,y
Parthenon,37.971528,23.726639
Stonehenge,51.178829,-1.826183
Colosseo,41.890251,12.492373"

const landmark_rows = [
  #("Parthenon", [37.971528, 23.726639]),
  #("Stonehenge", [51.178829, -1.826183]),
  #("Colosseo", [41.890251, 12.492373]),
]

assert landmark_rows
 == tysv.build({
   use name <- tysv.parsed
   use coordinates <- tysv.parsed
   #(name, coordinates)
 })
 |> tysv.col(Ok)
 |> tysv.multi_col(2, fn(tokens) {
   tokens |> list.map(float.parse) |> result.all
 })
 |> tysv.from(Text(landmarks))
 |> yielder.to_list
pub fn parsed(f: fn(a) -> b) -> fn(a) -> b
pub fn row_sep(
  builder: Builder(a),
  row_sep: String,
) -> Builder(a)

Set row separator. WARN: This does not work when the source provided in from is a FileStream

pub fn skip_header(
  builder: Builder(a),
  skip_header: Bool,
) -> Builder(a)

Enable/Disable skipping header.

Search Document