package janestreet_csv

  1. Overview
  2. Docs
Tools for working with CSVs on the command line

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=8940b4aa979a3bd5993b52d36cd768fd3bd5d1fb11c36c9c269ee646c7511a41

doc/src/janestreet_csv.csv_tool_lib/csv_sum.ml.html

Source file csv_sum.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open Core
open Csv_common

let sum csv =
  let line =
    List.fold
      csv.lines
      ~init:(List.map csv.header ~f:(fun _ -> 0.))
      ~f:
        (List.map2_exn ~f:(fun sum x ->
           sum
           +.
           try Float.of_string x with
           | _ -> 0.))
    |> List.map ~f:Float.to_string_12
  in
  { header = csv.header; lines = [ line ] }
;;

let run ?separator file =
  Or_file.with_all file ?separator ~f:(fun csv -> sum csv |> print_csv ?separator)
;;
OCaml

Innovation. Community. Security.