Skip to content

Instantly share code, notes, and snippets.

View ghost-not-in-the-shell's full-sized avatar

ghost!@shell ghost-not-in-the-shell

View GitHub Profile
@ghost-not-in-the-shell
ghost-not-in-the-shell / sort.ml
Created January 30, 2019 23:20
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
@ghost-not-in-the-shell
ghost-not-in-the-shell / add_all.ml
Created January 30, 2019 22:36
A simple OCaml program using Async
open Core
open Async
let add_all file =
Reader.file_contents file >>= fun contents ->
let ls = String.split_lines contents in
let ss = String.split_on_chars (String.concat ls) ~on:[','] in
let ns = List.map ss ~f:Int.of_string in
let sum = List.fold_left ns ~init:0 ~f:(+) in
printf "%d\n" sum;