Esc

for_expansion

procedureextensionsince 0.36.1Source
  • macOS: for_expansion works on macOS
  • Linux: for_expansion works on Linux
  • Windows: for_expansion works on Windows
  • Wasm: for_expansion works on Wasm

Iterates a reader: for row: reader runs the body per record (a [] string or a Row) until the input ends or a record fails, and reader.error then says which. A typed row is released by the body. Example:

Signature

for_expansion :: (r: *Csv_Reader($Row), body: Code, flags: For_Flags)
Example↗
#import "Extensions/Csv";

User :: struct {
    name: string;
    age: int;
}

reader := csv_reader(User, cast([] u8) "name,age\nada,36\nbob,x\n", .{ header = true });
defer csv_reader_free(*reader);
count := 0;
for user, index: reader {
    defer csv_row_free(*user);
    assert(user.name == "ada" && index == 0);
    count += 1;
}
assert(count == 1 && reader.error.kind == .TYPE);

See also