diff --git a/lib_stdlib/tzString.ml b/lib_stdlib/tzString.ml index 5941d05fd..323ac2ec3 100644 --- a/lib_stdlib/tzString.ml +++ b/lib_stdlib/tzString.ml @@ -73,3 +73,8 @@ let mem_char s c = match String.index s c with | exception Not_found -> false | _ -> true + +let fold_left f init s = + let acc = ref init in + String.iter (fun c -> acc := f !acc c) s ; + !acc diff --git a/lib_stdlib/tzString.mli b/lib_stdlib/tzString.mli index 1d3f834ce..e2548eac5 100644 --- a/lib_stdlib/tzString.mli +++ b/lib_stdlib/tzString.mli @@ -29,3 +29,6 @@ val common_prefix: string -> string -> int (** Test whether a string contains a given character *) val mem_char: string -> char -> bool + +(** Functional iteration over the characters of a string from first to last *) +val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a