Commit c67eb1af authored by François Bobot's avatar François Bobot
Browse files

stdlib : add Map.mapi_fold

parent de5783d8
......@@ -56,6 +56,8 @@ module type S =
val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
val inter : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
val find_default : key -> 'a -> 'a t -> 'a
val mapi_fold:
(key -> 'a -> 'acc -> 'acc * 'b)-> 'a t -> 'acc -> 'acc * 'b t
end
module Make(Ord: OrderedType) = struct
......@@ -388,6 +390,17 @@ module Make(Ord: OrderedType) = struct
else find_default x def (if c < 0 then l else r)
let rec mapi_fold f m acc =
match m with
Empty -> acc, Empty
| Node(l, v, d, r, h) ->
let acc,l' = mapi_fold f l acc in
let acc,d' = f v d acc in
let acc,r' = mapi_fold f r acc in
acc,Node(l', v, d', r', h)
end
end
......@@ -217,6 +217,10 @@ module type S =
(** [find_default x d m] returns the current binding of [x] in [m],
or return [d] if no such binding exists. *)
val mapi_fold:
(key -> 'a -> 'acc -> 'acc * 'b)-> 'a t -> 'acc -> 'acc * 'b t
(** fold and map at the same time *)
end
(** Output signature of the functor {!Map.Make}. *)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment