package janestreet_csv

  1. Overview
  2. Docs

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.