///- --package .

table_rows (test)

test table_rows: prelude
///- --test static --symbol

:< testing
:| table_row =
    | Table : string

:= text_of (r : table_row) : string =
    ?= r ?|
    | Table text => text

:= data_step \* s. (f : s -> string -> s) ((started, acc) : bool * s) (line : string) : bool * s =
    ? started && line <> "" ?> !+, f acc line |: !+, acc

:= fold_data \* s. (f : s -> string -> s) (init : s) (r : table_row) : s =
    := _, out = listm::fold (data_step f) (!-, init) (sm'::split_list "\n" (text_of r))
    out

a_table_folds_over_its_data_lines_only (test)

test a_table_folds_over_its_data_lines_only: passed
///- --test --symbol
///> lua
///> rust

:= ~text = "a\tb\nx\ty\n\nz\tw\n"
fold_data (\ n _ => n + 1i32) 0i32 (Table text) |> _assert_eq 2i32
__assert_eq { expected = 2 }
lua: unavailable on this machine (`spiral lua --lua-path /tmp/spiral_cells/1793692956013-7298/main.lua` was not found)
0