File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,14 @@ module Stdlib = struct
148
148
in
149
149
aux n [] l
150
150
151
+ let rec map_sharing f l0 =
152
+ match l0 with
153
+ | a :: l ->
154
+ let a' = f a in
155
+ let l' = map_sharing f l in
156
+ if a' == a && l' == l then l0 else a' :: l'
157
+ | [] -> []
158
+
151
159
let rec is_prefix ~equal t ~of_ =
152
160
match t, of_ with
153
161
| [] , [] -> true
Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ module Stdlib : sig
116
116
the [n] first elements of [l] and [after] the remaining ones.
117
117
If [l] has less than [n] elements, raises Invalid_argument. *)
118
118
119
+ val map_sharing : ('a -> 'a ) -> 'a t -> 'a t
120
+ (* * [map_sharing f l] is [map f l]. If for all elements of the list
121
+ [f e == e] then [map_sharing f l == l] *)
122
+
119
123
val is_prefix
120
124
: equal:('a -> 'a -> bool )
121
125
-> 'a list
You can’t perform that action at this time.
0 commit comments