Compare commits

..

1 commit

Author SHA1 Message Date
Fardale
afade23d80
Merge 273ba69ea3 into 31ad563044 2025-01-20 01:29:21 +00:00
4 changed files with 1 additions and 36 deletions

View file

@ -67,13 +67,6 @@ let rec iterate n f x =
else
iterate (n - 1) f (f x)
let[@inline] with_return (type ret) f : ret =
let exception E of ret in
let return x = raise_notrace (E x) in
match f return with
| res -> res
| exception E res -> res
module Infix = struct
(* default implem for some operators *)
let ( %> ) f g = compose g f

View file

@ -83,22 +83,6 @@ val iterate : int -> ('a -> 'a) -> 'a -> 'a
[x], [iterate 1 f x] is [f x], [iterate 2 f x] is [f (f x)], etc.
@since 2.1 *)
val with_return : (('ret -> 'a) -> 'ret) -> 'ret
(** [with_return f] is [f return], where [return] is a function
that can be invoked to exit the scope early.
For example:
{[
let find_array arr x =
let@ return = with_return in
for i = 0 to Array.length arr-1 do
if arr.(i) = x then return i;
done;
-1
]}
@since NEXT_RELEASE *)
(** {2 Infix}
Infix operators. *)

View file

@ -375,7 +375,7 @@ val mguard : bool -> unit t
@since 3.1 *)
val return : 'a -> 'a t
(** [return x] is [[x]]. *)
(** [return x] is [x]. *)
val take : int -> 'a t -> 'a t
(** [take n l] takes the [n] first elements of the list [l], drop the rest. *)

View file

@ -21,15 +21,3 @@ true
t @@ fun () -> CCFun.((succ %> string_of_int) 2 = "3");;
t @@ fun () -> CCFun.((( * ) 3 % succ) 5 = 18);;
t @@ fun () -> CCFun.(succ @@ ( * ) 2 @@ pred @@ 3 = 5)
let find_array arr x =
let@ return = with_return in
for i = 0 to Array.length arr - 1 do
if arr.(i) = x then return i
done;
-1
;;
eq 1 @@ find_array [| "a"; "b"; "c" |] "b";;
eq 2 @@ find_array [| "a"; "b"; "c" |] "c";;
eq (-1) @@ find_array [| "a"; "b"; "c" |] "hello"