day 1
This commit is contained in:
parent
29d8387656
commit
512ae7d3d7
5 changed files with 257 additions and 5 deletions
17
bracket.ml
Normal file
17
bracket.ml
Normal file
|
@ -0,0 +1,17 @@
|
|||
let bracket ~make ~act ~free =
|
||||
let x = make () in
|
||||
match act x with
|
||||
| result -> free x; result
|
||||
| exception e -> free x; raise e
|
||||
|
||||
let infile ~act name =
|
||||
bracket ~make:(fun () -> open_in name) ~act ~free:close_in_noerr
|
||||
|
||||
let infile_lines ~line:f ~of_seq name =
|
||||
let get_line file =
|
||||
match input_line file with
|
||||
| exception End_of_file -> None
|
||||
| line -> Some (f line, file)
|
||||
in
|
||||
let act file = of_seq (Seq.unfold get_line file) in
|
||||
infile name ~act
|
Loading…
Add table
Add a link
Reference in a new issue