From: Richard J. <ri...@an...> - 2005-02-17 23:40:59
|
On Tue, Feb 15, 2005 at 08:34:03AM -0500, Eric C. Cooper wrote: > On Tue, Feb 15, 2005 at 10:33:16AM +0000, Richard Jones wrote: > > If you can suggest suitable fold_left and fold_right functions, then > > they can be added to ExtLib. > > Here's what I use: > > val string_fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a > val string_fold_right : (char -> 'a -> 'a) -> 'a -> string -> 'a > > let string_fold_left f init str = > let n = String.length str in > let rec loop i result = > if i = n then result > else loop (i + 1) (f result str.[i]) > in > loop 0 init > > let string_fold_right f init str = > let n = String.length str in > let rec loop i result = > if i = 0 then result > else > let i' = i - 1 in > loop i' (f str.[i'] result) > in > loop n init No one had any objections, so I added these and implode/explode to ExtString. Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com |