feat(opt): fix bind arguments order

This commit is contained in:
Fardale 2020-01-06 21:39:55 +01:00
parent bf8db5dcff
commit 4bc01a0b82
2 changed files with 12 additions and 15 deletions

View file

@ -4,10 +4,6 @@
type 'a t = 'a option type 'a t = 'a option
let bind f = function
| None -> None
| Some x -> f x
let map f = function let map f = function
| None -> None | None -> None
| Some x -> Some (f x) | Some x -> Some (f x)
@ -42,14 +38,14 @@ let equal f o1 o2 = match o1, o2 with
let return x = Some x let return x = Some x
let (>>=) o f = match o with
| None -> None
| Some x -> f x
let flat_map f o = match o with let flat_map f o = match o with
| None -> None | None -> None
| Some x -> f x | Some x -> f x
let bind o f = flat_map f o
let (>>=) = bind
let pure x = Some x let pure x = Some x
let (<*>) f x = match f, x with let (<*>) f x = match f, x with

View file

@ -4,10 +4,6 @@
type +'a t = 'a option type +'a t = 'a option
val bind : ('a -> 'b t) -> 'a t -> 'b t
(** [bind f o] if [o] is [Some v] then [f v] else [None]
@since NEXT_RELEASE *)
val map : ('a -> 'b) -> 'a t -> 'b t val map : ('a -> 'b) -> 'a t -> 'b t
(** Transform the element inside, if any. *) (** Transform the element inside, if any. *)
@ -39,12 +35,17 @@ val return : 'a -> 'a t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t val (>|=) : 'a t -> ('a -> 'b) -> 'b t
(** Infix version of {!map}. *) (** Infix version of {!map}. *)
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
(** Monadic bind. *)
val flat_map : ('a -> 'b t) -> 'a t -> 'b t val flat_map : ('a -> 'b t) -> 'a t -> 'b t
(** Flip version of {!>>=}. *) (** Flip version of {!>>=}. *)
val bind : 'a t -> ('a -> 'b t) -> 'b t
(** Monadic bind.
[bind f o] if [o] is [Some v] then [f v] else [None]
@since NEXT_RELEASE *)
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
(** Infix version of {!bind}. *)
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> '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]. *) (** [map2 f o1 o2] maps ['a option] and ['b option] to a ['c option] using [f]. *)