Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/prelude_js/head.ts>head

A standard module for functional programming
Latest
function head
import { head } from "https://deno.land/x/prelude_js@1.2.0/head.ts";

Returns the first element of the given template literal.

Examples

Example 1

import { head } from "https://deno.land/x/prelude_js@$VERSION/head.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(head(""), "");
assertEquals(head("abc"), "a");

Type Parameters

T extends string

Parameters

input: `${T}${string}`

Any template literal.

Returns the first element of the given string.

Examples

Example 1

import { head } from "https://deno.land/x/prelude_js@$VERSION/head.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(head("" as string), "");

Parameters

input: string

Any string.

Returns

string

Returns the first element of the given tuple.

Examples

Example 1

import { head } from "https://deno.land/x/prelude_js@$VERSION/head.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(head([]), undefined);
assertEquals(head([1, 2, 3]), 1);

Parameters

input: readonly [T, ...unknown[]]

Any tuple.

Returns the first element of the given iterable.

Examples

Example 1

import { head } from "https://deno.land/x/prelude_js@$VERSION/head.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(head(new Set(["x", "y", "z"])), "x");

Parameters

input: Iterable<T>

Any iterable.

Returns

T | undefined