import { MaybePromiseLike, Pair, Mapper, AnyParameters, AsyncMonad, Alternative, Container, Pipe, AsyncTap, Zip } from './types'; export declare const enum EitherType { Left = "Left", Right = "Right" } declare const name = "Either"; declare function right(right: R): Either; declare namespace right { var _a: () => Either; export { _a as void }; } declare function left(value: L): Either; export { right, right as Ok, left, left as Err }; declare class EitherConstructor implements AsyncMonad, Alternative, Container, Pipe, AsyncTap, Zip { mapLeft(map: Mapper, ...parameters: P): Either; map(map: Mapper, ...parameters: P): Either; mapRight(map: Mapper, ...parameters: P): Either; biMap(mapLeft: Mapper, mapRight: Mapper): Either; asyncMap(map: Mapper, P>, ...parameters: P): Promise>; pure(value: R): Either; apply(this: Either>, argument: Either, ...parameters: P): Either; apply(this: Either, map: Either>, ...parameters: P): Either; asyncApply(this: Either, P>>, argument: Either, ...parameters: P): Promise>; asyncApply(this: Either, map: Either, P>>, ...parameters: P): Promise>; chain(map: Mapper, P>, ...parameters: P): Either; chainLeft(map: Mapper, P>, ...parameters: P): Either; asyncChain(map: Mapper>, P>, ...parameters: P): Promise>; await(this: Either>): Promise>; join(this: Either>): Either; default(value: R): Either; or(x: Either): Either; orLazy(factory: () => Either): Either; orAsync(factory: () => MaybePromiseLike>): Promise>; tap

(callback: Mapper, ...parameters: P): Either; asyncTap

(callback: Mapper, P>, ...parameters: P): Promise>; tapLeft

(callback: Mapper, ...parameters: P): Either; pipe(pipe: Mapper, T, P>, ...parameters: P): T; isLeft(predicate: (left: L) => left is T): this is Left; isLeft(predicate?: (left: L) => boolean): this is Left; isError(predicate: (left: L) => left is T): this is Left; isError(predicate?: (left: L) => boolean): this is Left; isRight(predicate?: (right: R) => right is T): this is Right; isRight(predicate?: (right: R) => boolean): this is Right; isOk(predicate?: (right: R) => right is T): this is Right; isOk(predicate?: (right: R) => boolean): this is Right; /** * * @param {Mapper} mapLeft * @param {Mapper} mapRight * @return {A|B} * @throws {InvalidStateError} - {@link InvalidStateError} if Either state is neither Left neither Right, this probably should never happen */ fold(mapLeft: Mapper, mapRight: Mapper): A | B; match(matcher: { readonly left: (left: L) => A; readonly right: (value: R) => B; }): A | B; unwrapOrElse(fallback: (value: L) => T): T | R; unwrapOr(value: T): T | R; /** * @deprecated - **If Left value is Error use {@link throw} instead** * * * @param {string} [message] - Error message, if either is left. By default "Either state is Left" * @return {R} - Right value of Either, if right * @throws {UnwrapCustomError} - {@link UnwrapCustomError} is Left with provided {@link message} */ unwrap(message?: string): R; zip(either: Either): Either>; swap(): Either; promise(): Promise; /** * * @return {R} - Right value if current state is Right, * @throws {L} - {@link L} if current state is Left */ throw(): R; /** * Return value of Either independent if it is Right or Left * * @deprecated - probably should not be used, please refactor code or use {@link fold} * @see {@link fold} * @return {L|R} */ value(): L | R; any(this: Either): T; } type SerializedLeft = Readonly<{ name: typeof name; type: EitherType.Left; left: L; }>; declare class Left extends EitherConstructor implements SerializedLeft { static create(left: L): Left; /** * @deprecated Should not be used directly, public only for serialization & type check use {@link getLeft} * @see {@link getLeft} * * @type {L} * @memberof Left */ readonly left: L; get [Symbol.toStringTag](): EitherType.Left; get name(): typeof name; getRight(): undefined; getValue(): undefined; getLeft(): L; getError(): L; /** * Should be used instead of * ```js * return left(result.getLeft()) * ``` * * Makes types correct without copying * * @template T * @return {Left} * * @example * return result.move() */ move(): Left; get type(): EitherType.Left; private constructor(); toJSON(): SerializedLeft; } type SerializedRight = Readonly<{ name: typeof name; type: EitherType.Right; right: R; }>; declare class Right extends EitherConstructor implements SerializedRight { static create(right: R): Right; /** * @deprecated Should not be used directly, public only for serialization & type check use {@link getRight} * @see {@link getRight} * * @type {R} * @memberof Right */ readonly right: R; get [Symbol.toStringTag](): EitherType.Right; get name(): typeof name; get type(): EitherType.Right; getRight(): R; getValue(): R; getLeft(): undefined; getError(): undefined; /** * Should be used instead of * ```js * return right(result.getRight()) * ``` * * Makes types correct without copying * * @template T * @return {Right} * * @example * return result.move() */ move(): Right; private constructor(); toJSON(): SerializedRight; } export type Either = Right | Left; export type SerializedEither = SerializedRight | SerializedLeft; export declare const isLeft: (value: unknown | Either) => value is Left; export declare const isRight: (value: unknown | Either) => value is Right; export declare const isEither: (value: unknown | Either) => value is Either; export declare function chain(map: (value: R, ...parameters: P) => MaybePromiseLike>, ...parameters: P): (either: Either, ...parameters: P) => Promise>; export declare function chain(map: (value: R, ...parameters: P) => MaybePromiseLike>, ...parameters: P): (either: Either, ...parameters: P) => Promise>; export declare function chain(map: (value: R, ...parameters: P) => MaybePromiseLike>, ...parameters: P): (either: Either, ...parameters: P) => Promise>; /** * * @template L * @template R * * @throws {DeserializationError} - {@link DeserializationError} * @param {SerializedEither} serialized * @return {Either} */ export declare function fromJSON(serialized: SerializedEither): Either; export declare function mergeInOne(values: [Either]): Either; export declare function mergeInOne(values: [Either, Either]): Either; export declare function mergeInOne(values: [Either, Either, Either]): Either; export declare function mergeInOne(values: [Either, Either, Either, Either]): Either; export declare function mergeInOne(values: [ Either, Either, Either, Either, Either ]): Either; export declare function mergeInOne(values: [ Either, Either, Either, Either, Either, Either ]): Either; export declare function mergeInOne(values: Either[]): Either; export declare const merge: typeof mergeInOne; export declare const from: typeof right; export declare function mergeInMany(values: [Either]): Either; export declare function mergeInMany(values: [Either, Either]): Either<(L1 | L2)[], [R1, R2]>; export declare function mergeInMany(values: [Either, Either, Either]): Either<(L1 | L2 | L3)[], [R1, R2, R3]>; export declare function mergeInMany(values: [Either, Either, Either, Either]): Either<(L1 | L2 | L3 | L4)[], [R1, R2, R3, R4]>; export declare function mergeInMany(values: [ Either, Either, Either, Either, Either ]): Either<(L1 | L2 | L3 | L4 | L5)[], [R1, R2, R3, R4, R5]>; export declare function mergeInMany(values: [ Either, Either, Either, Either, Either, Either ]): Either<(L1 | L2 | L3 | L4 | L5 | L6)[], [R1, R2, R3, R4, R5, R6]>; export declare function mergeInMany(values: Either[]): Either; export declare function aggregateError(values: Either[], message: string | undefined | ((lefts: T[]) => string | undefined)): AggregateError | undefined; export type MapCaught = Mapper; type LegacyMethodDecorator = (target: CallableFunction, property: any, descriptor: PropertyDescriptor) => void; type ModernMethodDecorator = R>(method: T, context: any) => T; export declare function DecorateLegacy(): LegacyMethodDecorator; export declare function DecorateAsyncLegacy(): LegacyMethodDecorator; export declare function Decorate(): ModernMethodDecorator; export declare function DecorateAsync(): ModernMethodDecorator>; export declare function wrap(method: (...parameters: P) => Either, mapCaught?: MapCaught): (this: any, ...parameters: P) => Either; export declare function wrapAsync(method: (...parameters: P) => MaybePromiseLike>): (this: any, ...parameters: P) => Promise>; export declare function catchSync(method: () => Either, mapCaught?: MapCaught): Either; export declare function catchAsync(method: PromiseLike> | (() => MaybePromiseLike>), mapCaught?: MapCaught): Promise>; export declare function fromPromise(promise: MaybePromiseLike, mapCaught?: MapCaught): Promise>; export declare function fromTry(callback: () => T, mapCaught?: MapCaught): Either; export declare function fromTryAsync(callback: PromiseLike | (() => MaybePromiseLike), mapCaught?: MapCaught): Promise>; export declare function fromPromiseSettledResult(result: PromiseSettledResult): Either;