UNPKG

@quenk/preconditions

Version:
61 lines (60 loc) 2.46 kB
import * as lazy from '@quenk/noni/lib/data/lazy'; import { Type } from '@quenk/noni/lib/data/type'; import { Precondition } from './'; /** * isArray tests if the value is an array */ export declare const isArray: Precondition<Type, Type[]>; /** * toArray converts a value into an array. * * If the value is an empty string or nullish, an empty array is produced. */ export declare const toArray: <A>(value: A) => import("./result").Result<unknown, A & any[]> | import("./result").Result<unknown, A[]>; /** * notEmpty tests if an array has at least one member. */ export declare const nonEmpty: <A>(value: A[]) => import("./result").Result<A[], A[]>; /** * maxItems sets a maximum number of elements the array can contain. */ export declare const maxItems: <A>(target: number) => Precondition<A[], A[]>; /** * minItems sets a minimum number of elements the array can contain. */ export declare const minItems: <A>(target: number) => Precondition<A[], A[]>; /** * range tests whether an array's length falls within a specific min and max range. */ export declare const range: <A>(min: number, max: number) => (value: A[]) => import("./result").Result<A[], unknown> | import("./result").Result<unknown, A[]>; /** * filter applies a precondition to each member of an array producing * an array where only the successful members are kept. */ export declare const filter: <A, B>(p: Precondition<A, B>) => Precondition<A[], B[]>; /** * map applies a precondition to each member of an array. * * If the precondition fails for any of the members, * the entire array is considered a failure. */ export declare const map: <A, B>(p: Precondition<A, B>) => Precondition<A[], B[]>; /** * tuple tests whether the value supplied qualifies as a tuple. * * Each precondition in the list represents a precondition for its * corresponding tuple element. */ export declare const tuple: <A, B>(list: Precondition<A, B>[]) => Precondition<A[], B[]>; /** * Reduce type defines a Precondition styled reducer function. */ export type Reducer<A, B> = (accum: B) => Precondition<A, B>; /** * reduce a list of values into an accumalated value initially specified by the * parameter "accum". * * Be careful not to mutate the accumulated value directly to avoid subtle bugs. * Instead copy the value to be accumualted in each call to the reducer. */ export declare const reduce: <A, B>(getAccum: lazy.Lazy<B>, func: Reducer<A, B>) => Precondition<A[], B>;