Renamed predicate parameter of take_while, rtake_while from p to f, aligining it with pre-existing drop_while.

This commit is contained in:
Alexander Lucas 2025-01-01 09:55:26 -05:00
parent 330cba94de
commit d29ed7ee72
3 changed files with 14 additions and 14 deletions

View file

@ -585,17 +585,17 @@ let take n s =
else else
s s
let take_while p s = let take_while f s =
let i = ref 0 in let i = ref 0 in
while !i < String.length s && p (String.unsafe_get s !i) do while !i < String.length s && f (String.unsafe_get s !i) do
incr i incr i
done; done;
String.sub s 0 !i String.sub s 0 !i
let rtake_while p s = let rtake_while f s =
let s_len_pred = String.length s - 1 in let s_len_pred = String.length s - 1 in
let i = ref s_len_pred in let i = ref s_len_pred in
while !i >= 0 && p (String.unsafe_get s !i) do while !i >= 0 && f (String.unsafe_get s !i) do
decr i decr i
done ; done ;
if !i < s_len_pred if !i < s_len_pred

View file

@ -183,13 +183,13 @@ val take : int -> string -> string
@since 0.17 *) @since 0.17 *)
val take_while : (char -> bool) -> string -> string val take_while : (char -> bool) -> string -> string
(** [take_while p s] keeps only the longest prefix [t] of [s] such that every (** [take_while f s] keeps only the longest prefix [t] of [s] such that every
character [c] in [t] satisfies [p c]. character [c] in [t] satisfies [f c].
@since 3.16 *) @since 3.16 *)
val rtake_while : (char -> bool) -> string -> string val rtake_while : (char -> bool) -> string -> string
(** [rtake_while p s] keeps only the longest suffix [t] of [s] such that every (** [rtake_while f s] keeps only the longest suffix [t] of [s] such that every
character [c] in [t] satisfies [p c]. character [c] in [t] satisfies [f c].
@since 3.16 *) @since 3.16 *)
val drop : int -> string -> string val drop : int -> string -> string

View file

@ -193,14 +193,14 @@ val take : int -> string -> string
(** [take n s] keeps only the [n] first chars of [s]. (** [take n s] keeps only the [n] first chars of [s].
@since 0.17 *) @since 0.17 *)
val take_while : p:(char -> bool) -> string -> string val take_while : f:(char -> bool) -> string -> string
(** [take_while ~p s] keeps only the longest prefix [t] of [s] such that every (** [take_while ~f s] keeps only the longest prefix [t] of [s] such that every
character [c] in [t] satisfies [p c]. character [c] in [t] satisfies [f c].
@since 3.16 *) @since 3.16 *)
val rtake_while : p:(char -> bool) -> string -> string val rtake_while : f:(char -> bool) -> string -> string
(** [rtake_while ~p s] keeps only the longest suffix [t] of [s] such that every (** [rtake_while ~f s] keeps only the longest suffix [t] of [s] such that every
character [c] in [t] satisfies [p c]. character [c] in [t] satisfies [f c].
@since 3.16 *) @since 3.16 *)
val drop : int -> string -> string val drop : int -> string -> string