mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCList.hd_tl
This commit is contained in:
parent
16ac701de1
commit
23e3544adc
2 changed files with 14 additions and 0 deletions
|
|
@ -454,6 +454,15 @@ let rec drop n l = match l with
|
|||
| _ when n=0 -> l
|
||||
| _::l' -> drop (n-1) l'
|
||||
|
||||
let hd_tl = function
|
||||
| [] -> failwith "hd_tl"
|
||||
| x :: l -> x, l
|
||||
|
||||
(*$T
|
||||
try ignore (hd_tl []); false with Failure _ -> true
|
||||
hd_tl [1;2;3] = (1, [2;3])
|
||||
*)
|
||||
|
||||
let take_drop n l = take n l, drop n l
|
||||
|
||||
let split = take_drop
|
||||
|
|
|
|||
|
|
@ -106,6 +106,11 @@ val take : int -> 'a t -> 'a t
|
|||
val drop : int -> 'a t -> 'a t
|
||||
(** Drop the [n] first elements, keep the rest *)
|
||||
|
||||
val hd_tl : 'a t -> 'a * 'a t
|
||||
(** [hd_tl (x :: l)] returns [hd, l].
|
||||
@raise Failure if the list is empty
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val take_drop : int -> 'a t -> 'a t * 'a t
|
||||
(** [take_drop n l] returns [l1, l2] such that [l1 @ l2 = l] and
|
||||
[length l1 = min (length l) n] *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue