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
|
||||
)
|
||||
|
||||
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
|
||||
let (>|=) x f = map ~f x
|
||||
let (>>=) x f = flat_map ~f x
|
||||
let (<|>) = default
|
||||
end
|
||||
|
||||
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
|
||||
(** Monadic flatten + map. *)
|
||||
|
||||
val default : 'a t -> 'a t -> 'a t
|
||||
(** Choice operator.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
module Infix : sig
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
val (<|>) : 'a t -> 'a t -> 'a t
|
||||
end
|
||||
|
||||
include module type of Infix
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue