day 3, add [un]curry and swap to utils
This commit is contained in:
parent
efde27f8c8
commit
883d16a3a3
4 changed files with 366 additions and 0 deletions
15
lib/utils.ml
15
lib/utils.ml
|
@ -9,3 +9,18 @@ let read_file name =
|
|||
| None -> close_in ic; acc in
|
||||
aux []
|
||||
|
||||
module CS = Set.Make(Char);;
|
||||
|
||||
let set_of_string str =
|
||||
let rec aux s i st =
|
||||
if i < 0 then st
|
||||
else aux s (i - 1) (CS.add s.[i] st) in
|
||||
aux str ((String.length str) - 1) CS.empty
|
||||
|
||||
let map_pair f (a, b) = (f a, f b)
|
||||
|
||||
let curry f x y = f (x, y)
|
||||
let uncurry f (x, y) = f x y
|
||||
let uncurry3 f (x, y, z) = f x y z
|
||||
|
||||
let swap x y = y x
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue