-module(utils@csv). -compile(no_auto_import). -export([iterator_of_hmaps/1]). -spec lines(binary()) -> list(binary()). lines(S) -> gleam@string:split(S, <<"\n"/utf8>>). -spec cells(binary()) -> list(binary()). cells(S) -> gleam@string:split(S, <<","/utf8>>). -spec hmap(list(binary()), binary()) -> gleam@map:map_(binary(), binary()). hmap(Headers, Line) -> Values = cells(Line), gleam@map:from_list(gleam@list:zip(Headers, Values)). -spec iterator_of_hmaps(binary()) -> gleam@iterator:iterator(gleam@map:map_(binary(), binary())). iterator_of_hmaps(S) -> {[First_line], Rest_lines} = gleam@list:split(lines(S), 1), Headers = cells(First_line), gleam@iterator:from_list( gleam@list:map(Rest_lines, fun(Line) -> hmap(Headers, Line) end) ).