export type Some = Option; export type None = Option; type Optional = A | null | undefined; export declare abstract class Option { static of(value: Optional): Option; private readonly value; protected constructor(ref: NonNullable); /** * Returns `true` if the option is empty, `false` otherwise. */ isEmpty(): this is None; /** * Returns `true` if the option is not empty, `false` otherwise. */ nonEmpty(): this is Some; get(): NonNullable; /** * Returns the option's value if the option is nonempty, otherwise * return the given `fallback`. * * See [[Option.getOrElseL]] for a lazy alternative. */ getOrElse(fallback: AA): NonNullable | AA; /** * Returns the option's value if the option is nonempty, otherwise * return the result of evaluating `thunk`. * * See [[Option.getOrElse]] for a strict alternative. */ getOrElseL(thunk: () => AA): NonNullable | AA; /** * Returns this option if it is nonempty, otherwise returns the * given `fallback`. */ orElse(fallback: Option): Option; /** * Returns this option if it is nonempty, otherwise returns the * given result of evaluating the given `thunk`. * * @param thunk a no-params function that gets evaluated and * whose result is returned in case this option is empty */ orElseL(thunk: () => Option): Option; /** * Returns the option's value if the option is nonempty, otherwise * return `null`. * ``` */ orNull(): NonNullable | null; /** * Returns the option's value if the option is nonempty, otherwise * return `undefined`. */ orUndefined(): NonNullable | undefined; /** * Returns an option containing the result of applying `f` to * this option's value, or an empty option if the source is empty. * * NOTE: this is similar with `flatMap`, except with `map` the * result of `f` doesn't need to be wrapped in an `Option`. * * @param f the mapping function that will transform the value * of this option if nonempty. * * @return a new option instance containing the value of the * source mapped by the given function */ map(f: (a: NonNullable) => B): Option; /** * Returns the result of applying `f` to this option's value if * the option is nonempty, otherwise returns an empty option. * * NOTE: this is similar with `map`, except that `flatMap` the * result returned by `f` is expected to be boxed in an `Option` * already. * * Example: * * ```typescript * const opt = Option.of(10) * * opt.flatMap(num => { * if (num % 2 == 0) * Some(num + 1) * else * None * }) * ``` * * @param f the mapping function that will transform the value * of this option if nonempty. * * @return a new option instance containing the value of the * source mapped by the given function if the value is * differs from this option value otherwise returns this option */ flatMap(f: (a: NonNullable) => Option): Option; /** * Returns this option if it is nonempty AND applying the * predicate `p` to the underlying value yields `true`, * otherwise return an empty option. * * @param p is the predicate function that is used to * apply filtering on the option's value * * @return a new option instance containing the value of the * source filtered with the given predicate */ filter(p: (a: A) => a is B): Option; filter(p: (a: NonNullable) => boolean): Option; /** * Returns the result of applying `f` to this option's value, * or in case the option is empty, the return the result of * evaluating the `fallback` function. * * This function is equivalent with: * * ```typescript * opt.map(f).getOrElseL(fallback) * ``` * * @param fallback is the function to be evaluated in case this * option is empty * * @param f is the mapping function for transforming this option's * value in case it is nonempty */ fold(fallback: () => B, f: (a: NonNullable) => B): B; /** * Returns true if this option is nonempty and the value it * holds is equal to the given `elem`. */ contains(elem: NonNullable): boolean; /** * Returns `true` if this option is nonempty and the given * predicate returns `true` when applied on this option's value. * * @param p is the predicate function to test */ exists(p: (a: NonNullable) => boolean): boolean; /** * Returns true if this option is empty or the given predicate * returns `true` when applied on this option's value. * * @param p is the predicate function to test */ forAll(p: (a: NonNullable) => boolean): boolean; /** * Apply the given procedure `cb` to the option's value if * this option is nonempty, otherwise do nothing. * * @param cb the procedure to apply */ forEach(cb: (a: NonNullable) => void): void; equals(that: Option): boolean; } /** * The `Some` data constructor for [[Option]] represents existing * values of type `A`. */ export declare function some(value: NonNullable): Option; /** * @alias some */ export declare function Some(value: NonNullable): Option; /** * The `None` data constructor for [[Option]] represents non-existing * values for any type. */ export declare const None: None; /** * Builds an [[Option]] reference that contains the given value. * * If the given value is `null` or `undefined` then the returned * option will be empty. */ export declare function option(value: Optional): Option; export {};