luizbarboza / d4_dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.
https://pub.dev/packages/d4_dsv
ISC License
2 stars 0 forks source link

how to use autoType? #1

Open wuxialearn opened 2 months ago

wuxialearn commented 2 months ago

The docs for autoType show this usage


csvParse(string, autoType);

but it does not seem to work as csvParse only accepts a String. Neither does


csvParseWith(string, autoType);

which gives this error:

The argument type 'Map<String, Object?> Function(Map<String, String>)' can't be assigned to the parameter type 'dynamic Function(Map<String, String>, int, List)'.

wuxialearn commented 2 months ago

Ok, it works like this


csvParseWith<Map<String, dynamic>>((data), (d, _, __) => autoType(d))
luizbarboza commented 2 months ago

@wuxialearn The documentation is unclear and will be corrected. Thanks for pointing it out.

wuxialearn commented 2 months ago

it might also be worthwhile to provide a convenience method that only applies to each row like


csvParseWithFn(data, fn)

which internally calls


csvParseWith<Map<String, dynamic>>((data), (d, _, __) => fn(d))