acc, List.rev res
;;
+let filter_map_monad f acc l =
+ let acc, res =
+ List.fold_left
+ (fun (acc, res) t ->
+ match f acc t with
+ | acc, None -> acc, res
+ | acc, Some x -> acc, x::res)
+ (acc,[]) l
+ in
+ acc, List.rev res
+;;
+
let list_rev_map_filter f l =
let rec aux a = function
| [] -> a
val filter_map: ('a -> 'b option) -> 'a list -> 'b list (** filter + map *)
val filter_map_acc: ('acc -> 'a -> ('acc * 'b) option) -> 'acc -> 'a list ->
'acc * 'b list (** fold/filter + map *)
+val filter_map_monad: ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a list ->
+ 'acc * 'b list (** fold/filter + map *)
val list_rev_map_filter: ('a -> 'b option) -> 'a list -> 'b list
val list_rev_map_filter_fold: ('c -> 'a -> 'c * 'b option) -> 'c -> 'a list -> 'c * 'b list