Add <|> to CCLazy_list

This commit is contained in:
Nicola Mometto 2018-03-06 10:09:56 +00:00 committed by Simon Cruanes
parent 8d3981d983
commit 68ad3d7408
2 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -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