Skip to content

Instantly share code, notes, and snippets.

Last active February 23, 2022 15:40
What would you like to do?
NotEmptyArray definition
export interface NonEmptyArray<A> extends ReadonlyArray<A> {
// tslint:disable-next-line: readonly-keyword
0: A;
type ReadOnlyNotEmptyArray<T> = Readonly<NotEmptyArray<T>>;
function isNotEmptyArray<T>(as: T[]): as is NotEmptyArray<T> {
return as.length > 0;
function freeze(as: NotEmptyArray<T>): ReadOnlyNotEmptyArray<T> {
return Object.freeze(as);
const head = <T>(as: NotEmptyArray<T>): T => as[0];
const tail = <T>([,]: NotEmptyArray<T>): T[] => rest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment