Skip to content

Instantly share code, notes, and snippets.

@ghost-not-in-the-shell
Created January 30, 2019 23:20
Show Gist options
  • Save ghost-not-in-the-shell/1fb99fc17f84c53bd0656e7e4fc5c2ac to your computer and use it in GitHub Desktop.
Save ghost-not-in-the-shell/1fb99fc17f84c53bd0656e7e4fc5c2ac to your computer and use it in GitHub Desktop.
A small OCaml program using Async
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
@bkase
Copy link

bkase commented Jan 30, 2019

Try is with let%bind instead of >>| and >>=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment