• Gets the last element of the list. If the list is infinite, it hangs forever.

    Type Parameters

    • T

    Parameters

    • list: List<T>

      The source list.

    Returns Option<T>

    The last element of list if exists.

    Examples

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

    assertEquals(last(empty()), Option.none());
    assertEquals(last(fromString("hoge")), Option.some("e"));

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

Generated using TypeDoc