Commits

Sébastien Ferré committed e7c7cb3

Add of functions 'fold_for', 'fold_for_down', and 'stream_map'.

Comments (0)

Files changed (1)

     | None -> e
     | Some e' -> fold_while f e'
 
+let fold_for : (int -> 'a -> 'a) -> int -> int -> 'a -> 'a =
+  fun f a b e ->
+    let res = ref e in
+    for x = a to b do
+      res := f x !res
+    done;
+    !res
+
+let fold_for_down : (int -> 'a -> 'a) -> int -> int -> 'a -> 'a =
+  fun f a b e ->
+    let res = ref e in
+    for x = a downto b do
+      res := f x !res
+    done;
+    !res
+
 let rec insert : ('a -> 'a -> bool) -> 'a -> 'a list -> 'a list =
   fun order x ->
     function
 	  owner := None;
 	  Mutex.unlock m;
 	  res
+
+(* utilities on streams *)
+
+let rec stream_map f = parser
+  | [<'x; str>] -> [<'f x; stream_map f str>]
+  | [<>] -> [<>]
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.