TzString: add fold_left

This commit is contained in:
Vincent Bernardoff 2018-01-04 17:10:24 +01:00 committed by Benjamin Canou
parent 44b39a51c3
commit 2d349b606f
2 changed files with 8 additions and 0 deletions

View File

@ -73,3 +73,8 @@ let mem_char s c =
match String.index s c with match String.index s c with
| exception Not_found -> false | exception Not_found -> false
| _ -> true | _ -> true
let fold_left f init s =
let acc = ref init in
String.iter (fun c -> acc := f !acc c) s ;
!acc

View File

@ -29,3 +29,6 @@ val common_prefix: string -> string -> int
(** Test whether a string contains a given character *) (** Test whether a string contains a given character *)
val mem_char: string -> char -> bool 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