mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-03-07 21:27:55 -05:00
CCOption(cleanup): remove functions that are in the stdlib
This commit is contained in:
parent
5e60c0d237
commit
bb31265e52
2 changed files with 2 additions and 99 deletions
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
(** {1 Options} *)
|
||||
|
||||
type 'a t = 'a option
|
||||
|
||||
let[@inline] map f = function
|
||||
| None -> None
|
||||
| Some x -> Some (f x)
|
||||
include Option
|
||||
|
||||
let map_or ~default f = function
|
||||
| None -> default
|
||||
|
|
@ -16,30 +12,7 @@ let map_lazy default_fn f = function
|
|||
| None -> default_fn ()
|
||||
| Some x -> f x
|
||||
|
||||
let is_some = function
|
||||
| None -> false
|
||||
| Some _ -> true
|
||||
|
||||
let is_none = function
|
||||
| None -> true
|
||||
| Some _ -> false
|
||||
|
||||
let compare f o1 o2 =
|
||||
match o1, o2 with
|
||||
| None, None -> 0
|
||||
| Some _, None -> 1
|
||||
| None, Some _ -> -1
|
||||
| Some x, Some y -> f x y
|
||||
|
||||
let equal f o1 o2 =
|
||||
match o1, o2 with
|
||||
| None, None -> true
|
||||
| Some _, None | None, Some _ -> false
|
||||
| Some x, Some y -> f x y
|
||||
|
||||
let return x = Some x
|
||||
let some = return
|
||||
let none = None
|
||||
|
||||
let[@inline] flat_map f o =
|
||||
match o with
|
||||
|
|
@ -51,7 +24,6 @@ let[@inline] flat_map_l f o =
|
|||
| None -> []
|
||||
| Some x -> f x
|
||||
|
||||
let[@inline] bind o f = flat_map f o
|
||||
let ( >>= ) = bind
|
||||
let pure x = Some x
|
||||
let k_compose f g x = f x |> flat_map g
|
||||
|
|
@ -99,11 +71,6 @@ let for_all p = function
|
|||
| None -> true
|
||||
| Some x -> p x
|
||||
|
||||
let iter f o =
|
||||
match o with
|
||||
| None -> ()
|
||||
| Some x -> f x
|
||||
|
||||
let fold f acc o =
|
||||
match o with
|
||||
| None -> acc
|
||||
|
|
@ -121,11 +88,6 @@ let apply_or f x =
|
|||
|
||||
let ( |?> ) x f = apply_or f x
|
||||
|
||||
let value x ~default =
|
||||
match x with
|
||||
| None -> default
|
||||
| Some y -> y
|
||||
|
||||
let get_exn = function
|
||||
| Some x -> x
|
||||
| None -> invalid_arg "CCOption.get_exn"
|
||||
|
|
@ -164,11 +126,6 @@ let wrap2 ?(handler = fun _ -> true) f x y =
|
|||
else
|
||||
raise e
|
||||
|
||||
let to_list o =
|
||||
match o with
|
||||
| None -> []
|
||||
| Some x -> [ x ]
|
||||
|
||||
let of_list = function
|
||||
| x :: _ -> Some x
|
||||
| [] -> None
|
||||
|
|
@ -254,11 +211,6 @@ let to_iter o k =
|
|||
| None -> ()
|
||||
| Some x -> k x
|
||||
|
||||
let to_seq o () =
|
||||
match o with
|
||||
| None -> Seq.Nil
|
||||
| Some x -> Seq.Cons (x, Seq.empty)
|
||||
|
||||
let pp ppx out = function
|
||||
| None -> Format.pp_print_string out "None"
|
||||
| Some x -> Format.fprintf out "@[Some %a@]" ppx x
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@
|
|||
This module replaces `CCOpt`.
|
||||
@since 3.6 *)
|
||||
|
||||
type +'a t = 'a option
|
||||
|
||||
val map : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [map f o] applies the function [f] to the element inside [o], if any. *)
|
||||
include module type of Option
|
||||
|
||||
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b
|
||||
(** [map_or ~default f o] is [f x] if [o = Some x], [default] otherwise.
|
||||
|
|
@ -18,33 +15,9 @@ val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'b
|
|||
(** [map_lazy default_fn f o] is [f x] if [o = Some x], [default_fn ()] otherwise.
|
||||
@since 1.2 *)
|
||||
|
||||
val is_some : _ t -> bool
|
||||
(** [is_some (Some x)] returns [true] otherwise it returns [false]. *)
|
||||
|
||||
val is_none : _ t -> bool
|
||||
(** [is_none None] returns [true] otherwise it returns [false].
|
||||
@since 0.11 *)
|
||||
|
||||
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
|
||||
(** [compare comp o1 o2] compares two options [o1] and [o2],
|
||||
using custom comparators [comp] for the value.
|
||||
[None] is always assumed to be less than [Some _]. *)
|
||||
|
||||
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
(** [equal p o1 o2] tests for equality between option types [o1] and [o2],
|
||||
using a custom equality predicate [p]. *)
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** [return x] is a monadic return, that is [return x = Some x]. *)
|
||||
|
||||
val some : 'a -> 'a t
|
||||
(** Alias to {!return}.
|
||||
@since 3.5 *)
|
||||
|
||||
val none : 'a t
|
||||
(** Alias to {!None}.
|
||||
@since 3.5 *)
|
||||
|
||||
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
|
||||
(** [flat_map f o] is equivalent to {!map} followed by {!flatten}.
|
||||
Flip version of {!(>>=)}. *)
|
||||
|
|
@ -53,11 +26,6 @@ val flat_map_l : ('a -> 'b list) -> 'a t -> 'b list
|
|||
(** [flat_map_l f o] is [[]] if [o] is [None], or [f x] if [o] is [Some x].
|
||||
@since 3.12 *)
|
||||
|
||||
val bind : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** [bind o f] is [f v] if [o] is [Some v], [None] otherwise.
|
||||
Monadic bind.
|
||||
@since 3.0 *)
|
||||
|
||||
val k_compose : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t
|
||||
(** Kleisli composition. Monadic equivalent of {!CCFun.compose}
|
||||
@since 3.13.1 *)
|
||||
|
|
@ -65,9 +33,6 @@ val k_compose : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t
|
|||
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** [map2 f o1 o2] maps ['a option] and ['b option] to a ['c option] using [f]. *)
|
||||
|
||||
val iter : ('a -> unit) -> 'a t -> unit
|
||||
(** [iter f o] applies [f] to [o]. Iterate on 0 or 1 element. *)
|
||||
|
||||
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** [fold f init o] is [f init x] if [o] is [Some x], or [init] if [o] is [None].
|
||||
Fold on 0 or 1 element. *)
|
||||
|
|
@ -102,10 +67,6 @@ val apply_or : ('a -> 'a t) -> 'a -> 'a
|
|||
turning functions like "remove" into "remove_if_it_exists".
|
||||
@since 3.13.1 *)
|
||||
|
||||
val value : 'a t -> default:'a -> 'a
|
||||
(** [value o ~default] is similar to the Stdlib's [Option.value] and to {!get_or}.
|
||||
@since 2.8 *)
|
||||
|
||||
val get_exn : 'a t -> 'a
|
||||
[@@ocaml.deprecated "use CCOption.get_exn_or instead"]
|
||||
(** [get_exn o] returns [x] if [o] is [Some x] or fails if [o] is [None].
|
||||
|
|
@ -207,9 +168,6 @@ include module type of Infix
|
|||
|
||||
(** {2 Conversion and IO} *)
|
||||
|
||||
val to_list : 'a t -> 'a list
|
||||
(** [to_list o] returns [[x]] if [o] is [Some x] or the empty list [[]] if [o] is [None]. *)
|
||||
|
||||
val of_list : 'a list -> 'a t
|
||||
(** [of_list l] returns [Some x] (x being the head of the list l), or [None] if [l] is the empty list. *)
|
||||
|
||||
|
|
@ -246,13 +204,6 @@ val to_gen : 'a t -> 'a gen
|
|||
(** [to_gen o] is [o] as a [gen]. [Some x] is the singleton [gen] containing [x]
|
||||
and [None] is the empty [gen]. *)
|
||||
|
||||
val to_seq : 'a t -> 'a Seq.t
|
||||
(** [to_seq o] is [o] as a sequence [Seq.t]. [Some x] is the singleton sequence containing [x]
|
||||
and [None] is the empty sequence.
|
||||
Same as {!Stdlib.Option.to_seq}
|
||||
Renamed from [to_std_seq] since 3.0.
|
||||
@since 3.0 *)
|
||||
|
||||
val to_iter : 'a t -> 'a iter
|
||||
(** [to_iter o] returns an internal iterator, like in the library [Iter].
|
||||
@since 2.8 *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue