Commits

Sébastien Ferré committed b2b2e5f

Add of 'list_of_weak'.

Comments (0)

Files changed (1)

 	None -> ()
       | Some x -> f x
     done
+
+let list_of_weak : 'a Weak.t -> 'a list =
+  fun w ->
+    let res = ref [] in
+    for i=0 to Weak.length w - 1 do
+      match Weak.get w i with
+	None -> ()
+      |	Some x -> res := x::!res
+    done;
+    !res
+
+(* List functionals *)
+(* ---------------- *)
+
+let rec mapfilter : ('a -> 'b option) -> 'a list -> 'b list =
+  fun f -> function
+      [] -> []
+    | x::l -> match f x with
+	None -> mapfilter f l
+      |	Some y -> y::mapfilter f l
+