Choice monad. See the Haskell library or this paper
See online documentation.
> #require "choice";;
> open Choice.Infix;;
> let c = Choice.lift2 (fun x y -> x,y)
(Choice.of_list [1;2;3;4]) (Choice.of_list ["1"; "3"]);;
val c : (int * string) Choice.t = <abstr>
> let c2 = Choice.filter c (fun (x,y) -> x = int_of_string y);;
val c2 : (int * string) Choice.t = <abstr>
> let c3 = Choice.take 2 c2;;
val c3 : (int * string) Choice.t = <abstr>
> Choice.run_n 4 c3;;
- : (int * string) list = [(3, "3"); (1, "1")]
You need OCaml >= 4.03.0 and dune.
$ make
$ make install
The code is free, released under the BSD-2 license.