Created
January 30, 2019 23:20
-
-
Save ghost-not-in-the-shell/1fb99fc17f84c53bd0656e7e4fc5c2ac to your computer and use it in GitHub Desktop.
A small OCaml program using Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core | |
open Async | |
let parse contents = String.split_lines contents | |
|> String.concat | |
|> String.split_on_chars ~on:[','] | |
|> List.map ~f:Int.of_string | |
let read_then_sort fs = | |
let ds = List.map ~f:Reader.file_contents fs | |
in Deferred.all ds | |
>>| List.map ~f:parse | |
>>| List.concat | |
>>| List.sort ~compare:Int.compare | |
>>| List.to_string ~f:Int.to_string | |
>>= fun ns -> printf "%s\n" ns; return () | |
let () = | |
Command.async_spec | |
~summary:"Read and then sort!" | |
Command.Spec.(empty +> anon (sequence ("filename" %: string))) | |
(fun fs () -> read_then_sort fs) | |
|> Command.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try is with
let%bind
instead of>>|
and>>=