|
|
|
@ -39,28 +39,6 @@ let fold_option xs ~init ~f =
|
|
|
|
|
(fold xs ~init ~f:(fun acc elt ->
|
|
|
|
|
match f acc elt with Some res -> res | None -> return None ))
|
|
|
|
|
|
|
|
|
|
let map_endo map t ~f =
|
|
|
|
|
let change = ref false in
|
|
|
|
|
let t' =
|
|
|
|
|
map t ~f:(fun x ->
|
|
|
|
|
let x' = f x in
|
|
|
|
|
if not (x' == x) then change := true ;
|
|
|
|
|
x' )
|
|
|
|
|
in
|
|
|
|
|
if !change then t' else t
|
|
|
|
|
|
|
|
|
|
let filter_map_endo filter_map t ~f =
|
|
|
|
|
let change = ref false in
|
|
|
|
|
let t' =
|
|
|
|
|
filter_map t ~f:(fun x ->
|
|
|
|
|
let x'_opt = f x in
|
|
|
|
|
( match x'_opt with
|
|
|
|
|
| Some x' when x' == x -> ()
|
|
|
|
|
| _ -> change := true ) ;
|
|
|
|
|
x'_opt )
|
|
|
|
|
in
|
|
|
|
|
if !change then t' else t
|
|
|
|
|
|
|
|
|
|
let filter_map_endo t ~f = filter_map_endo filter_map t ~f
|
|
|
|
|
let map_endo t ~f = map_endo map t ~f
|
|
|
|
|
|
|
|
|
|