Declarative CSV codecs
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add READMEs for 16 packages, fix merlint issues, add KVN tests

READMEs for all new packages. Fix missing docs (ocm, stix, globe),
naming (project_visible→visible, label_info→info, shader_kind→kind),
add .ocamlformat to csvt, add 11 KVN tests.

+46
+1
.ocamlformat
··· 1 + version = 0.28.1
+45
README.md
··· 1 + # csvt 2 + 3 + Declarative CSV codecs. 4 + 5 + Bidirectional codec system for CSV files, inspired by Jsont's approach to JSON codecs. Define typed codecs for your OCaml types and use them to decode CSV rows and encode values back to CSV. 6 + 7 + ## Installation 8 + 9 + ``` 10 + opam install csvt 11 + ``` 12 + 13 + ## Usage 14 + 15 + ```ocaml 16 + type point = { x : float; y : float; label : string } 17 + 18 + let point_codec = 19 + Csvt.(Row.( 20 + obj (fun x y label -> { x; y; label }) 21 + |> col "x" float ~enc:(fun p -> p.x) 22 + |> col "y" float ~enc:(fun p -> p.y) 23 + |> col "label" string ~enc:(fun p -> p.label) 24 + |> finish 25 + )) 26 + 27 + let () = 28 + match Csvt.decode_file point_codec "points.csv" with 29 + | Ok points -> List.iter (fun p -> Printf.printf "%s\n" p.label) points 30 + | Error e -> prerr_endline (Csvt.error_to_string e) 31 + ``` 32 + 33 + ## API Overview 34 + 35 + - **`type 'a col_codec`** -- Column-level codecs: `string`, `int`, `float`, `bool`, `option`, `nullable_float` 36 + - **`type 'a t`** -- Row-level codecs mapping CSV rows to OCaml records 37 + - **`Row.obj`**, **`Row.col`**, **`Row.finish`** -- Builder for row codecs 38 + - **`resolve`** -- Resolve column names to indices (O(1) per-row decoding) 39 + - **`decode_file`**, **`decode_channel`**, **`decode_string`** -- Decode CSV data 40 + - **`encode_header`**, **`encode_row`** -- Encode values back to CSV 41 + - **`fold_file`**, **`fold_channel`** -- Streaming fold over rows 42 + 43 + ## License 44 + 45 + ISC