Commit 805f6a43 authored by Louis Duchemin's avatar Louis Duchemin
Browse files

Implements toolbox.Utils.range_for_all with tests

parent 08949d34
......@@ -25,6 +25,18 @@ let range_iter a b ~f =
in
loop a
let range_for_all a b ~f =
let rec loop i = i = b || (f i && loop (i + 1)) in
loop a
let%test "range_for_all 1..4 <= 10" = range_for_all 1 4 ~f:(( >= ) 10)
let%test "not (range_for_all 1..4 <= 2)" =
not @@ range_for_all 1 4 ~f:(( >= ) 2)
let%test "not (range_for_all 1..4 <= 0)" =
not @@ range_for_all 1 4 ~f:(( >= ) 2)
let int_fold a b ~init ~f =
let rec loop acc i = if i >= b then acc else loop (f acc i) (i + 1) in
loop init a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment