Handle list head and tail updates with explicit empty-list errors

This commit is contained in:
sneeker committed 2019-03-01 05:48:41 +00:00
1 parent adc5d38b9b
commit c835f992fd
4 files changed
+26

No files matched your search

+12
View File
@@ -13,3 +13,15 @@ let compose (outer_get, outer_put) (inner_get, inner_put) =
let _1 = (fun (left, _) -> left), (fun left (_, right) -> left, right)
let _2 = (fun (_, right) -> right), (fun right (left, _) -> left, right)
let _id = (fun value -> value), (fun value _ -> value)
let split = function
| head :: tail -> head, tail
| [] -> invalid_arg "Fieldglass: empty list"
let _hd =
(fun source -> fst (split source)),
(fun head source -> head :: snd (split source))
let _tl =
(fun source -> snd (split source)),
(fun tail source -> fst (split source) :: tail)