Merge pull request #179 from Fourchaux/master

Adding `CCList.tail_opt`
This commit is contained in:
Simon Cruanes 2018-01-26 08:26:14 -06:00 committed by GitHub
commit 7198417fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View file

@ -855,6 +855,10 @@ let head_opt = function
| [] -> None
| x::_ -> Some x
let tail_opt = function
| [] -> None
| _ :: tail -> Some tail
let rec last_opt = function
| [] -> None
| [x] -> Some x
@ -864,6 +868,9 @@ let rec last_opt = function
(Some 1) (head_opt [1;2;3])
(Some 1) (head_opt [1])
None (head_opt [])
(Some [2;3]) (tail_opt [1;2;3])
(Some []) (tail_opt [1])
None (tail_opt [])
(Some 3) (last_opt [1;2;3])
(Some 1) (last_opt [1])
None (last_opt [])

View file

@ -249,6 +249,10 @@ val head_opt : 'a t -> 'a option
(** First element.
@since 0.20 *)
val tail_opt : 'a t -> 'a t option
(** Return the given list without its first element.
@since NEXT_RELEASE *)
val last_opt : 'a t -> 'a option
(** Last element.
@since 0.20 *)

View file

@ -159,6 +159,10 @@ val head_opt : 'a t -> 'a option
(** First element.
@since 0.20 *)
val tail_opt : 'a t -> 'a t option
(** Return the given list without its first element.
@since NEXT_RELEASE *)
val last_opt : 'a t -> 'a option
(** Last element.
@since 0.20 *)