UNPKG

@creditkarma/dynamic-config

Version:

Dynamic Config for Node.js backed by Consul and Vault

137 lines (136 loc) 4.09 kB
export declare type MaybeMapping<A, B> = (val: A) => B; export declare type MaybePredicate<T> = (val: T) => boolean; export declare abstract class Maybe<T> { static fromNullable<T>(val: T | undefined | null): Maybe<T>; static nothing<T>(): Nothing<T>; static just<T>(val: T): Just<T>; /** * Returns a new Maybe containing the values, as an array, of the given Maybes. If any of the given * Maybes is a Nothing a Nothing is returned. */ static all<A, B>(a: Maybe<A>, b: Maybe<B>): Maybe<[A, B]>; static all<A, B, C>(a: Maybe<A>, b: Maybe<B>, c: Maybe<C>): Maybe<[A, B, C]>; static all<A, B, C, D>(a: Maybe<A>, b: Maybe<B>, c: Maybe<C>, d: Maybe<D>): Maybe<[A, B, C, D]>; abstract join<A>(this: Maybe<Maybe<A>>): Maybe<A>; abstract fork<B>(justFn: (val: T) => B, _: () => B): B; abstract map<B>(mapping: MaybeMapping<T, B>): Maybe<B>; abstract chain<B>(mapping: (val: T) => Maybe<B>): Maybe<B>; abstract filter(predicate: MaybePredicate<T>): Maybe<T>; abstract get(): T; abstract getOrElse(defaultValue: T): T; abstract isJust(): boolean; abstract isNothing(): boolean; } export declare class Just<T> extends Maybe<T> { static create<B>(val: B): Just<B>; private value; constructor(val: T); toString(): string; /** * join :: Maybe (Maybe a) -> Maybe a * * Takes a nested Maybe and removes one level of nesting. * * @name join * @method * @memberof Maybe# * @returns {Maybe} */ join<A>(this: Maybe<Maybe<A>>): Maybe<A>; /** * @name fork * @method * @memberof Maybe# * @param {Function} justFn Function to call with value of Just * @param {Function} nothingFn Function to call with value of Nothing * @returns {*} The return value of the matching function */ fork<B>(justFn: (val: T) => B, _: () => B): B; /** * map :: Maybe a -> (a -> b) -> Maybe b * * Transforms the value of a Maybe with the given function. * * @name map * @method * @memberof Maybe# * @param {Function} mapping Function used to map value of Maybe * @returns {Maybe} */ map<B>(mapping: MaybeMapping<T, B>): Maybe<B>; /** * chain :: Maybe a -> (a -> Maybe b) -> Maybe b * * Takes the value of a Maybe and gives it to a function that returns a new Maybe. * * @name chain * @method * @memberof Maybe# * @param {Function} mapping Function used to create new Maybe * @returns {Maybe} */ chain<B>(mapping: (val: T) => Maybe<B>): Maybe<B>; /** * filter :: Maybe a -> (a -> Boolean) -> Maybe a * * Turns a Just into a Nothing if the predicate returns false * * @name filter * @method * @memberof Maybe# * @param {Function} predicate Function used to test value * @returns {Maybe} */ filter(predicate: MaybePredicate<T>): Maybe<T>; /** * get :: Maybe a -> a * * Extract the value from a Maybe * * @name get * @method * @memberof Maybe# * @returns {*} */ get(): T; /** * getOrElse :: Maybe a -> a -> a * * @name getOrElse * @method * @memberof Maybe# * @returns {*} */ getOrElse(_: T): T; /** * isNothing :: Maybe a -> Boolean * * @name isNothing * @method * @memberof Maybe# * @returns {Boolean} */ isNothing(): boolean; /** * isJust :: Maybe a -> Boolean * * @name isJust * @method * @memberof Maybe# * @returns {Boolean} */ isJust(): boolean; } export declare class Nothing<T> extends Maybe<T> { static create<B>(): Nothing<B>; toString(): string; fork<B>(_: (val: T) => B, nothingFn: () => B): B; join<A>(this: Maybe<Maybe<A>>): Maybe<A>; map<B>(_: MaybeMapping<T, B>): Maybe<B>; filter(_: MaybePredicate<T>): Maybe<T>; chain<B>(_: (val: T) => Maybe<B>): Maybe<B>; get(): T; getOrElse(val: T): T; isJust(): boolean; isNothing(): boolean; }