mirror of
https://github.com/c-cube/iter.git
synced 2025-12-05 19:00:31 -05:00
add {max_exn,min_exn}
This commit is contained in:
parent
12743ab24f
commit
ffe157a1c6
2 changed files with 23 additions and 0 deletions
|
|
@ -554,6 +554,10 @@ let max ?(lt=fun x y -> x < y) seq =
|
|||
| Some y -> if lt y x then ret := Some x);
|
||||
!ret
|
||||
|
||||
let max_exn ?lt seq = match max ?lt seq with
|
||||
| Some x -> x
|
||||
| None -> raise Not_found
|
||||
|
||||
let min ?(lt=fun x y -> x < y) seq =
|
||||
let ret = ref None in
|
||||
seq
|
||||
|
|
@ -562,6 +566,15 @@ let min ?(lt=fun x y -> x < y) seq =
|
|||
| Some y -> if lt x y then ret := Some x);
|
||||
!ret
|
||||
|
||||
let min_exn ?lt seq = match min ?lt seq with
|
||||
| Some x -> x
|
||||
| None -> raise Not_found
|
||||
|
||||
(*$= & ~printer:string_of_int
|
||||
100 (0 -- 100 |> max_exn ?lt:None)
|
||||
0 (0 -- 100 |> min_exn ?lt:None)
|
||||
*)
|
||||
|
||||
exception ExitHead
|
||||
|
||||
let head seq =
|
||||
|
|
|
|||
|
|
@ -290,10 +290,20 @@ val max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a option
|
|||
@return None if the sequence is empty, Some [m] where [m] is the maximal
|
||||
element otherwise *)
|
||||
|
||||
val max_exn : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
|
||||
(** Unsafe version of {!max}
|
||||
@raise Not_found if the sequence is empty
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val min : ?lt:('a -> 'a -> bool) -> 'a t -> 'a option
|
||||
(** Min element of the sequence, using the given comparison function.
|
||||
see {!max} for more details. *)
|
||||
|
||||
val min_exn : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
|
||||
(** Unsafe version of {!min}
|
||||
@raise Not_found if the sequence is empty
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val head : 'a t -> 'a option
|
||||
(** First element, if any, otherwise [None]
|
||||
@since 0.5.1 *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue