import { Maybe, Either } from 'monet'; export declare function combine(a: Maybe): Maybe<[A]>; export declare function combine(a: Maybe, b: Maybe): Maybe<[A, B]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe): Maybe<[A, B, C]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe): Maybe<[A, B, C, D]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe, e: Maybe): Maybe<[A, B, C, D, E]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe, e: Maybe, f: Maybe): Maybe<[A, B, C, D, E, F]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe, e: Maybe, f: Maybe, g: Maybe): Maybe<[A, B, C, D, E, F, G]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe, e: Maybe, f: Maybe, g: Maybe, h: Maybe): Maybe<[A, B, C, D, E, F, G, H]>; export declare function combine(a: Maybe, b: Maybe, c: Maybe, d: Maybe, e: Maybe, f: Maybe, g: Maybe, h: Maybe, i: Maybe): Maybe<[A, B, C, D, E, F, G, H, I]>; export declare function combine(...maybes: Maybe[]): Maybe; export declare function combineFrom(value1: T1, value2: T2, value3: T3, value4: T4, value5: T5): Maybe<[T1, T2, T3, T4, T5]>; export declare function combineFrom(value1: T1, value2: T2, value3: T3, value4: T4): Maybe<[T1, T2, T3, T4]>; export declare function combineFrom(value1: T1, value2: T2, value3: T3): Maybe<[T1, T2, T3]>; export declare function combineFrom(value1: T1, value2: T2): Maybe<[T1, T2]>; export declare function combineFrom(value: T): Maybe<[T]>; export declare function combineFrom(): Maybe; export declare function combineFrom(...values: any[]): Maybe; /** * Executes a function if the given Maybe is a Some. * @alias ifPresent * @param fn - the function to execute * @returns the original Maybe * ```typescript * pipe( * Maybes.Some(5), * Maybes.tap(num => console.log(num)) // logs: 5 * ); * ``` */ export declare function tap(fn: (val: T) => void): (maybe: Maybe) => Maybe; /** * Throws an error if the Maybe is a None * @param error - the error (or a function resolving to an error) to throw * @returns the value of the Some, else throws the error provided * ```typescript * pipe( * Maybes.Some(5), * Maybes.orThrow(new Error()) // -> 5 * ); * * pipe( * Maybes.None(), * Maybes.orThrow(new Error()) // throws: Error * ); * ``` */ export declare function orThrow(error: E | (() => E)): (maybe: Maybe) => T; /** * Converts a Maybe into a boolean with an optional mapper function. * @param fn - an optional mapper function * @returns true if the Maybe is a Some and the optional mapper function returns true, otherwise false * ```typescript * pipe( * Maybes.Some('a'), * Maybes.toBoolean(str => str === 'a') // -> true * ); * * pipe( * Maybes.Some('b'), * Maybes.toBoolean(str => str === 'a') // -> false * ); * * pipe( * Maybes.None(), * Maybes.toBoolean() // -> false * ); * ``` */ export declare function toBoolean(fn?: (val: T) => boolean): (maybe: Maybe) => boolean; /** * Gets the value of a Maybe with a function that resolves the default value. * @alias defaultWith * @param elseFn - the function to resolve a default value * @returns the value of a Some, or the result of the elseFn if given a None * ```typescript * pipe( * Maybes.Some(5), * Maybes.orSomeWith(() => 3) // -> 5 * ); * * pipe( * Maybes.None(), * Maybes.orSomeWith(() => 3) // -> 3 * ); * ``` */ export declare function orSomeWith(elseFn: () => R): (maybe: Maybe) => T | R; /** * Gets a new Maybe from a function that resolves to a default Maybe. * @param elseFn - the function to resolve a default Maybe * @returns the original Maybe if it was a Some, or the default Maybe if it was a None * ```typescript * pipe( * Maybes.Some(4), * Maybes.orElseWith(() => Maybes.Some(3)) // -> Some(4) * ); * * pipe( * Maybes.None(), * Maybes.orElseWith(() => Maybes.Some(3)) // -> Some(3) * ); * ``` */ export declare function orElseWith(elseFn: () => Maybe): (maybe: Maybe) => Maybe; /** * Gets a new Maybe from a function that resolves to a nullable value. * @param elseFn - the function to resolve a nullable value * @returns the original Maybe if it was a Some, otherwise a new Maybe generated from the value of function provided * ```typescript * pipe( * Maybes.Some(4), * Maybes.orElseFrom(() => 3) // -> Some(4) * ); * * pipe( * Maybes.None(), * Maybes.orElseFrom(() => 5) // -> Some(5) * ); * * pipe( * Maybes.None(), * Maybes.orElseFrom(() => null) // -> None * ); * ``` */ export declare function orElseFrom(elseFn: () => T): (maybe: Maybe) => Maybe; /** * Maps a Some to a new Maybe using a mapper function. * @alias flatMapFrom * @param mapper - a function to map a Some value into a new nullable value * @returns a Some if the result of the mapper is not null and the original Maybe was a Some, otherwise a None * ```typescript * pipe( * Maybes.Some(4), * Maybes.map(num => num + 2) // -> Some(6) * ); * ``` */ export declare function map(mapper: (value: T) => U | null | undefined): (maybe: Maybe) => Maybe>; /** * Performs a catamorphism on a Maybe. * @param noneFn - the function to unwrap a None * @param someFn - the function to unwrap a Some * @returns the result of unwrapping the Maybe * ```typescript * pipe( * Maybes.Some(3), * Maybes.cata( * () => 2, * num => num * 2 // -> 6 * ) * ); * * pipe( * Maybes.None(), * Maybes.cata( * () => 2, // -> 2 * num => num * 2 * ) * ); * ``` */ export declare const cata: (noneFn: () => R1, someFn: (val: T) => R2) => (maybe: Maybe) => R1 | R2; /** * Filters a Some value with a predicate function. * @param predicate - the predicate function * @returns a Some if the predicate returns true and the original Maybe was a Some, otherwise a None * ```typescript * pipe( * Maybes.Some('test'), * Maybes.filter(str => str.length < 4) // -> None * ); * ``` */ export declare const filter: (predicate: (val: T) => boolean) => (maybe: Maybe) => Maybe; /** * Filters a Some value when the given predicate function returns false. * @param predicate - the negated predicate to use to filter * @returns a Some if the predicate returns true and the original Maybe was a Some, otherwise a None * ```typescript * pipe( * Maybes.Some('abc'), * Maybes.unless(str => str.length < 3) // -> Some('abc') * ); * * pipe( * Maybes.Some('ab'), * Maybes.unless(str => str.length < 3) // -> None * ); * ``` */ export declare function unless(predicate: (value: T) => boolean): (maybe: Maybe) => Maybe; /** * Flat maps a Some value into a new Maybe with a mapper function. * @param mapper - the mapper function * @returns the result of the mapper function if the original Maybe was a Some, otherwise a None * ```typescript * pipe( * Maybes.Some({ x: 'test' }), * Maybes.flatMap(obj => Maybes.fromNull(obj.x)) // -> Some('test') * ); * ``` */ export declare const flatMap: (mapper: (val: A) => Maybe) => (maybe: Maybe) => Maybe; /** * Gets the value of the Maybe or null. * @alias toValue * @returns the value of a Some, otherwise null * ```typescript * pipe( * Maybes.Some(3), * Maybes.orNull() // -> 3 * ); * * pipe( * Maybes.None(), * Maybes.orNull() // -> null * ); * ``` */ export declare const orNull: (noArg?: undefined) => (maybe: Maybe) => T | null; /** * Gets the value of the Maybe or undefined. * @returns the value of a Some, otherwise undefined * ```typescript * pipe( * Maybes.Some(3), * Maybes.orUndefined() // -> 3 * ); * * pipe( * Maybes.None(), * Maybes.orUndefined() // -> undefined * ); * ``` */ export declare const orUndefined: (noArg?: undefined) => (maybe: Maybe) => T | undefined; /** * Converts a Some into a Right, or a None into a Left of the provided left value. * @param leftVal - the value of the left side if given a None * @returns a Right of a Some value, or a Left of the given value * ```typescript * pipe( * Maybes.Some('a'), * Maybes.toEither(new Error()) // -> Right('a') * ); * * pipe( * Maybes.None(), * Maybes.toEither(new Error()) // -> Left(Error) * ); * ``` */ export declare const toEither: (leftVal: L) => (maybe: Maybe) => Either; /** * Gets the value of a Some, or the value provided. * @alias defaultTo * @param val - the default value * @returns the value of the Some given, else if given a None then the default value provided * ```typescript * pipe( * Maybes.Some(3), * Maybes.orSome(4) // -> 3 * ); * * pipe( * Maybes.None(), * Maybes.orSome(4) // -> 4 * ); * ``` */ export declare const orSome: (val: R) => (maybe: Maybe) => T | R; /** * Gets a default Maybe value. * @param val - the default Maybe value * @returns the original Maybe if given a Some, otherwise the default Maybe value * ```typescript * pipe( * Maybes.Some('a'), * Maybes.orElse(Maybes.Some('b')) // -> Some('a') * ); * * pipe( * Maybes.None(), * Maybes.orElse(Maybes.Some('b')) // -> Some('b') * ); * ``` */ export declare const orElse: (val: Maybe) => (maybe: Maybe) => Maybe; /** * Checks whether or not the given Maybe is a Some. * @alias isPresent * @returns true if given a Some, otherwise false * ```typescript * pipe( * Maybes.Some('a'), * Maybes.isSome() // -> true * ); * ``` */ export declare const isSome: (noArg?: undefined) => (maybe: Maybe) => boolean; /** * Checks whether or not the given Maybe is a None. * @returns true if given a None, otherwise false * ```typescript * pipe( * Maybes.Some('a'), * Maybes.isNone() // -> false * ); * ``` */ export declare const isNone: (noArg?: undefined) => (maybe: Maybe) => boolean; /** * Gets the value of a Some. * @returns the value of a Some * ```typescript * pipe( * Maybes.Some(4), * Maybes.some() // -> 4 * ); * ``` */ export declare const some: (noArg?: undefined) => (maybe: Maybe) => T; /** * Creates a Maybe from a potentially nullable source. * @alias of * @param value - the value to convert into a Maybe * @returns a Some if the value is non-null, otherwise a None * ```typescript * Maybes.fromNull(4); // -> Some(4) * Maybes.fromNull(undefined); // -> None * ``` */ export declare const fromNull: (value: T) => Maybe>; /** * Performs a strict equality on the value of a Maybe and the given value. * @param val - the value to check the value of the Maybe against * @returns true if the value of a Some is the same as the provided value, otherwise false * ```typescript * pipe( * Maybes.Some('abc'), * Maybes.isEqualTo('abc') // -> true * ); * ``` */ export declare const isEqualTo: (val: T) => (maybe: Maybe) => boolean; /** * Performs a strict equality on the value of a Maybe and the result of the given function. * @param val - the function that generates the value to check the Maybe against * @returns true if the value of a Some is the same as the result of the provided function, otherwise false * ```typescript * pipe( * Maybes.Some('abc'), * Maybes.isEqualWith(() => 'abc') // -> true * ); * ``` */ export declare const isEqualWith: (val: () => T) => (maybe: Maybe) => boolean; /** * Performs a deep equality on the value of a Maybe and the given value. * @param val - the value to check the value of the Maybe against * @returns true if the value of a Some is the same as the provided value, otherwise false * ```typescript * pipe( * Maybes.Some({ x: 1 }), * Maybes.matchesTo({ x: 1 }) // -> true * ); * ``` */ export declare const matchesTo: (val: T) => (maybe: Maybe) => boolean; /** * Performs a deep equality on the value of a Maybe and the result of the given function. * @param val - the function that generates the value to check the Maybe against * @returns true if the value of a Some is the same as the result of the provided function, otherwise false * ```typescript * pipe( * Maybes.Some({ x: 1 }), * Maybes.matchesWith(() => ({ x: 1 })) // -> true * ); * ``` */ export declare const matchesWith: (val: () => T) => (maybe: Maybe) => boolean; /** * Checks if two Maybes are equal using a comparer function. * @param comparer - a function to use to compare the values of two Somes * @param a - a Maybe to compare * @param b - a Maybe to compare * @returns true if both Maybes are Nones, or both Maybes are Somes and contain the same value as determined by the comparer * ```typescript * Maybes.same((a, b) => a.length === b.length, Maybes.Some('abc'), Maybes.Some('def')); // -> true * Maybes.same((a, b) => a.length === b.length, Maybes.Some('abc'), Maybes.Some('test')); // -> false * Maybes.same((a, b) => a.length === b.length, Maybes.Some('abc'), Maybes.None()); // -> false * Maybes.same((a, b) => a.length === b.length, Maybes.None(), Maybes.None()); // -> true * ``` */ export declare function same(comparer: (v1: T, v2: T) => boolean, a: Maybe, b: Maybe): boolean; /** * Checks if the value of two Maybes are strictly equal. * @param a - a Maybe to compare * @param b - a Maybe to compare * @returns true if both Maybes contain the same value, or both Maybes are a None * ```typescript * Maybes.equals(Maybes.Some(123), Maybes.Some(123)); // -> true * Maybes.equals(Maybes.Some({ x: 'a' }), Maybes.Some({ x: 'a' })); // -> false * Maybes.equals(Maybes.Some(123), Maybes.None()); // -> false * Maybes.equals(Maybes.None(), Maybes.None()); // -> true * ``` */ export declare const equals: (a: Maybe, b: Maybe) => boolean; /** * Creates a Maybe if the value successfully passes the predicate. * @param predicate - the predicate to create Some values from * @param value - the value to use to create the Maybe * @returns a Some if the value is non-null and passes the predicate, otherwise a None * ```typescript * Maybes.fromPredicate(Arrays.isArray, [1]); // -> Some([1]) * Maybes.fromPredicate(Arrays.isArray, 1); // -> None * Maybes.fromPredicate(Arrays.isArray, null); // -> None * ``` */ export declare function fromPredicate(predicate: (value: T) => boolean, value: T): Maybe; /** * Creates a Maybe from a numeric value. * @param value - the value to create a Maybe from * @returns a Some if the value is a finite number, otherwise a None * ```typescript * Maybes.fromNaN(123); // -> Some(123) * Maybes.fromNaN(Infinity); // -> None * Maybes.fromNaN('123'); // -> None * Maybes.fromNaN(NaN); // -> None * Maybes.fromNaN(null); // -> None * ``` */ export declare function fromNaN(value: any): Maybe; /** * Creates a Some value. * @param value - the value to construct a Some from * @returns a Some containing the given value */ export declare const Some: (value: T) => Maybe; /** * Creates a None value. * @returns a None */ export declare const None: () => Maybe; /** * Combines any number of nullable values into a single Maybe. * @alias combineFrom * @param ...values - any number of nullable values * @returns a Some of an array of all the values, or a None if any value was null * ```typescript * Maybes.fromNulls('a', 2, []); // -> Some(['a', 2, []]) * Maybes.fromNulls('a', null, 2); // -> None * ``` */ export declare const fromNulls: typeof combineFrom; /** * Creates a Maybe from a potentially nullable source. * @alias fromNull * @param value - the value to convert into a Maybe * @returns a Some if the value is non-null, otherwise a None * ```typescript * Maybes.of(4); // -> Some(4) * Maybes.of(undefined); // -> None * ``` */ export declare const of: (value: T) => Maybe>; /** * Gets the value of a Some, or the value provided. * @alias orSome * @param val - the default value * @returns the value of the Some given, else if given a None then the default value provided * ```typescript * pipe( * Maybes.Some(3), * Maybes.defaultTo(4) // -> 3 * ); * * pipe( * Maybes.None(), * Maybes.defaultTo(4) // -> 4 * ); * ``` */ export declare const defaultTo: (val: R) => (maybe: Maybe) => T | R; /** * Gets the value of a Maybe with a function that resolves the default value. * @alias orSomeWith * @param elseFn - the function to resolve a default value * @returns the value of a Some, or the result of the elseFn if given a None * ```typescript * pipe( * Maybes.Some(5), * Maybes.defaultWith(() => 3) // -> 5 * ); * * pipe( * Maybes.None(), * Maybes.defaultWith(() => 3) // -> 3 * ); * ``` */ export declare const defaultWith: typeof orSomeWith; /** * Gets the value of the Maybe or null. * @alias orNull * @returns the value of a Some, otherwise null * ```typescript * pipe( * Maybes.Some(3), * Maybes.toValue() // -> 3 * ); * * pipe( * Maybes.None(), * Maybes.toValue() // -> null * ); * ``` */ export declare const toValue: (noArg?: undefined) => (maybe: Maybe) => T | null; /** * Checks whether or not the given Maybe is a Some. * @alias isSome * @returns true if given a Some, otherwise false * ```typescript * pipe( * Maybes.Some('a'), * Maybes.isPresent() // -> true * ); * ``` */ export declare const isPresent: (noArg?: undefined) => (maybe: Maybe) => boolean; /** * Executes a function if the given Maybe is a Some. * @alias tap * @param fn - the function to execute * @returns the original Maybe * ```typescript * pipe( * Maybes.Some(5), * Maybes.ifPresent(num => console.log(num)) // logs: 5 * ); * ``` */ export declare const ifPresent: typeof tap; /** * Maps a Some to a new Maybe using a mapper function. * @alias map * @param mapper - a function to map a Some value into a new nullable value * @returns a Some if the result of the mapper is not null and the original Maybe was a Some, otherwise a None * ```typescript * pipe( * Maybes.Some(4), * Maybes.flatMapFrom(num => num + 2) // -> Some(6) * ); * ``` */ export declare const flatMapFrom: typeof map;