Module List.With_errors

Extended With_errors, adding functions specific to working with lists in an error-prone context.

include Travesty.Traversable_types.S1_on_monad with type 'a t := 'a list and module M := Base.Or_error
val map_m : 'a list -> f:('a -> 'b Travesty.Monad_exts.App(Base.Or_error).t) -> 'b list Travesty.Monad_exts.App(Base.Or_error).t
val fold_map_m : 'a list -> f:('acc -> 'a -> ('acc * 'b) Base.Or_error.t) -> init:'acc -> ('acc * 'b list) Base.Or_error.t
val fold_m : 'a list -> init:'acc -> f:('acc -> 'a -> 'acc Base.Or_error.t) -> 'acc Base.Or_error.t
val iter_m : 'a list -> f:('a -> Base.unit Base.Or_error.t) -> Base.unit Base.Or_error.t
val mapi_m : f:(Base.int -> 'a -> 'b Base.Or_error.t) -> 'a list -> 'b list Base.Or_error.t
val sequence_m : 'a Base.Or_error.t list -> 'a list Base.Or_error.t

Utility functions for modifying lists with error-prone functions

val replace_m : 'a list -> int -> f:('a -> 'a option Or_error.t) -> 'a list Or_error.t

replace_m xs at ~f tries to replace the value at index at in xs using the possibly-failing function f. f may return Ok None, in which case the item is removed

Examples:

replace [1; 2; 3] 1
  ~f:(fun _ -> Ok None) (* Ok [1; 3] *)
  replace [1; 2; 3] 2
  ~f:(fun x -> Ok (Some (x + 1)))

(* Ok [1; 2; 4] *)