I was going through Real World OCaml and wanted to make the program in "A Complete Program" use
Async. It works now, but I'm wondering how idiomatic it is, and if I'm doing anything weird?
open Core.Std open Async.Std let read_and_accumulate () = Reader.lines (Lazy.force Reader.stdin) |> Pipe.filter ~f:(Fn.non String.is_empty) |> Pipe.map ~f:Float.of_string |> Pipe.fold ~init:0. ~f:(fun x y -> return (x +. y)) let () = ignore (read_and_accumulate () >>| printf "Result is %f\n" >>| fun () -> exit 0); ignore (Scheduler.go ())
Also, I feel like I should be able to
Fn.compose return (+.) for the
Pipe.fold line but it doesn't work. Why not?