-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtail.ts
More file actions
25 lines (23 loc) · 841 Bytes
/
tail.ts
File metadata and controls
25 lines (23 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright © 2023 Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.
import type { Sliceable } from "./types.ts";
/** Extract the elements after the head of a sequence.
* @example
* ```ts
* import { tail } from "https://deno.land/x/seqtools/tail.ts";
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
*
* assertEquals(tail([1, 2, 3]), [2, 3]);
* assertEquals(tail("abc"), "bc");
* assertEquals(tail([0]), []);
* assertEquals(tail([]), []);
* ```
*/
export function tail<const T extends readonly unknown[]>(
array: readonly [unknown, ...T],
): T;
export function tail<const T extends string>(string: `${string}${T}`): T;
export function tail<T>(seq: Readonly<Sliceable<T>>): T;
export function tail<T>(seq: Readonly<Sliceable<T>>): T {
return seq.slice(1);
}