• Gets the first element of the list.

    Type Parameters

    • T

    Parameters

    • list: List<T>

      The source list.

    Returns Option<T>

    The first element of list if exists.

    Examples

    import { empty, fromString, head, singleton } from "./list.ts";
    import * as Option from "./option.ts";
    import { assertEquals } from "../deps.ts";

    assertEquals(head(empty()), Option.none());
    assertEquals(head(fromString("hoge")), Option.some("h"));

    const list = singleton(42);
    assertEquals(head(list), Option.some(42));
    assertEquals(head(list.rest()), Option.none());

Generated using TypeDoc