summaryrefslogtreecommitdiffstats
path: root/bin/main.ml
blob: 1c6c6c93c4cb7d9a059f7c1220750c5952002947 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
open Core
module Time_ns = Time_ns_unix

module List = struct
  include List

  let map_result ~(f : 'a -> ('b, 'c) result) : 'a list -> ('b list, 'c) result
      =
    let open Result.Let_syntax in
    let rec go = function
      | [] -> return []
      | x :: xs ->
          let%map x' = f x and xs' = go xs in
          x' :: xs'
    in
    go
end

module Result = struct
  include Result

  let unwrap = function
    | Error _ -> failwith "Result.unwrap: unexpected (Error _)"
    | Ok v -> v
end

let () =
  let ams_tz = Time_ns.Zone.find_exn "Europe/Amsterdam" in
  let prim_txs =
    In_channel.with_file ~binary:true "test.csv"
      ~f:(Rdcapsis.Ingcsv.read_channel ~ams_tz)
    |> Result.unwrap
  in
  let euc_id = "EUC" in
  let ledger =
    List.map_result ~f:(Rdcapsis.Convert.les_from_current_acc euc_id) prim_txs
    |> Result.unwrap |> List.concat
  in
  print_endline (Sexp.to_string_hum ([%sexp_of: Rdcapsis.Ledger.t] ledger))