MattWindsor91 / travesty

Haskell-style container traversability and state monads for Core
https://MattWindsor91.github.io/travesty
MIT License
10 stars 1 forks source link

Feature idea: replace #2

Open MattWindsor91 opened 5 years ago

MattWindsor91 commented 5 years ago

Add to Mappable.SX:

(* on Mappable *)
val replace : 'a t -> with:'b -> 'b t
let replace x ~with = map x ~f:(Fn.const with)

(* on Traversable with monad M *)
val replace_m : 'a t -> with:('b M.t) -> 'b t M.t
let replace_m x ~with = map_m x ~f:(M.return with)

This is simple syntactic sugar, but would make code where one is trying to use a Mappable to punch out a value in a container and replace it with a new value slightly nicer.