From b0d92f44ea8cacce3817957ec40cd4d08a27a7f3 Mon Sep 17 00:00:00 2001 From: nathan moreau Date: Fri, 26 Jan 2018 09:25:17 +0100 Subject: [PATCH 1/2] Adding CCList.tail_opt --- src/core/CCList.ml | 7 +++++++ src/core/CCList.mli | 4 ++++ src/core/CCListLabels.mli | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 064070d8..6f32f47e 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -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 []) diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 8dba2044..d97a5888 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -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 *) diff --git a/src/core/CCListLabels.mli b/src/core/CCListLabels.mli index 66f477c0..995c3be7 100644 --- a/src/core/CCListLabels.mli +++ b/src/core/CCListLabels.mli @@ -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 *) From b8260c737f4d8dafb23848b6783926e775b4ea44 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 26 Jan 2018 08:14:47 -0600 Subject: [PATCH 2/2] fix doc target in opam --- containers.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers.opam b/containers.opam index 16487c8f..59a6d54a 100644 --- a/containers.opam +++ b/containers.opam @@ -6,7 +6,7 @@ maintainer: "simon.cruanes.2007@m4x.org" build: [ ["jbuilder" "build" "-p" name "-j" jobs] ] -build-doc: [ "jbuilder" "doc" ] +build-doc: [ "jbuilder" "build" "@doc" ] build-test: [ "jbuilder" "runtest" ] depends: [ "jbuilder" {build}