diff options
| author | Pierre-Marie Pédrot | 2019-03-01 18:29:47 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2019-03-01 18:29:47 +0100 |
| commit | ae998e3049cd581d21c4fe0e8e18466ed9131546 (patch) | |
| tree | 02ba1b63c41c787c833c383629a7277fd1fde36e /clib/hMap.ml | |
| parent | f37c4445228f5aba5137f397755ebc8cb8c0c482 (diff) | |
| parent | 196de2c3a8033561861c345248dd05adcad95d3d (diff) | |
Merge PR #9626: [lib] Add `Map.update` from OCaml 4.06
Reviewed-by: SkySkimmer
Ack-by: ejgallego
Reviewed-by: ppedrot
Diffstat (limited to 'clib/hMap.ml')
| -rw-r--r-- | clib/hMap.ml | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clib/hMap.ml b/clib/hMap.ml index 5d634b7af0..09ffb39c21 100644 --- a/clib/hMap.ml +++ b/clib/hMap.ml @@ -408,6 +408,18 @@ struct let filter_range f s = filter (fun x _ -> f x = 0) s + let update k f m = + let aux = function + | None -> (match f None with + | None -> None + | Some v -> Some (Map.singleton k v)) + | Some m -> + let m = Map.update k f m in + if Map.is_empty m then None + else Some m + in + Int.Map.update (M.hash k) aux m + module Unsafe = struct let map f s = |
