mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 04:05:30 -05:00
Add <|> to CCLazy_list
This commit is contained in:
parent
8d3981d983
commit
68ad3d7408
2 changed files with 17 additions and 0 deletions
|
|
@ -82,9 +82,21 @@ let rec flat_map ~f l =
|
||||||
Lazy.force res
|
Lazy.force res
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let default b a =
|
||||||
|
lazy (
|
||||||
|
match a with
|
||||||
|
| lazy Nil -> Lazy.force b
|
||||||
|
| lazy a -> a
|
||||||
|
)
|
||||||
|
|
||||||
|
(*$=
|
||||||
|
[1] (default (return 1) empty |> to_list)
|
||||||
|
*)
|
||||||
|
|
||||||
module Infix = struct
|
module Infix = struct
|
||||||
let (>|=) x f = map ~f x
|
let (>|=) x f = map ~f x
|
||||||
let (>>=) x f = flat_map ~f x
|
let (>>=) x f = flat_map ~f x
|
||||||
|
let (<|>) = default
|
||||||
end
|
end
|
||||||
|
|
||||||
include Infix
|
include Infix
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,14 @@ val append : 'a t -> 'a t -> 'a t
|
||||||
val flat_map : f:('a -> 'b t) -> 'a t -> 'b t
|
val flat_map : f:('a -> 'b t) -> 'a t -> 'b t
|
||||||
(** Monadic flatten + map. *)
|
(** Monadic flatten + map. *)
|
||||||
|
|
||||||
|
val default : 'a t -> 'a t -> 'a t
|
||||||
|
(** Choice operator.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
module Infix : sig
|
module Infix : sig
|
||||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||||
|
val (<|>) : 'a t -> 'a t -> 'a t
|
||||||
end
|
end
|
||||||
|
|
||||||
include module type of Infix
|
include module type of Infix
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue