scats
Version:
Useful scala classes in typescript
68 lines (67 loc) • 3.08 kB
TypeScript
import { Option } from './option.js';
import { Collection } from './collection.js';
import { TryLike } from './try.js';
import { Mappable } from './mappable.js';
export interface EitherMatch<LEFT, RIGHT, T> {
right: (right: RIGHT) => T;
left: (left: LEFT) => T;
}
export declare abstract class Either<LEFT, RIGHT> implements Mappable<RIGHT> {
abstract match<T>(matcher: EitherMatch<LEFT, RIGHT, T>): T;
abstract get isLeft(): boolean;
get isRight(): boolean;
get left(): Either.LeftProjection<LEFT, RIGHT>;
fold<C>(fa: (left: LEFT) => C, fb: (right: RIGHT) => C): C;
get swap(): Either<RIGHT, LEFT>;
foreach(f: (right: RIGHT) => void): void;
getOrElse(or: () => RIGHT): RIGHT;
getOrElseValue(or: RIGHT): RIGHT;
orElse(or: () => Either<LEFT, RIGHT>): Either<LEFT, RIGHT>;
orElseValue(or: Either<LEFT, RIGHT>): Either<LEFT, RIGHT>;
contains(elem: RIGHT): boolean;
forall(f: (right: RIGHT) => boolean): boolean;
exists(p: (right: RIGHT) => boolean): boolean;
flatMap<RIGHT1>(f: (value: RIGHT) => Either<LEFT, RIGHT1>): Either<LEFT, RIGHT1>;
flatMapPromise<RIGHT1>(f: (item: RIGHT) => Promise<Either<LEFT, RIGHT1>>): Promise<Either<LEFT, RIGHT1>>;
map<RIGHT1>(f: (value: RIGHT) => RIGHT1): Either<LEFT, RIGHT1>;
mapPromise<RIGHT1>(f: (v: RIGHT) => Promise<RIGHT1>): Promise<Either<LEFT, RIGHT1>>;
filterOrElse(p: (v: RIGHT) => boolean, zero: () => LEFT): Either<LEFT, RIGHT>;
filterOrElseValue(p: (v: RIGHT) => boolean, zero: LEFT): Either<LEFT, RIGHT>;
get toCollection(): Collection<RIGHT>;
get toOption(): Option<RIGHT>;
toTry(toError?: (e: LEFT) => Error): TryLike<RIGHT>;
}
export declare class Left<T> extends Either<T, any> {
private readonly error;
constructor(error: T);
match<X>(matcher: EitherMatch<T, any, X>): X;
get isLeft(): boolean;
withRight<RIGHT>(): Either<T, RIGHT>;
}
export declare class Right<T> extends Either<any, T> {
private readonly value;
constructor(value: T);
match<X>(matcher: EitherMatch<any, T, X>): X;
get isLeft(): boolean;
withLeft<LEFT>(): Either<LEFT, T>;
}
export declare namespace Either {
class LeftProjection<A, B> {
private readonly e;
constructor(e: Either<A, B>);
mapPromise<A1, B1 extends B>(f: (item: A) => Promise<A1>): Promise<Either<A1, B1>>;
flatMapPromise<A1, B1 extends B>(f: (item: A) => Promise<Either<A1, B1>>): Promise<Either<A1, B1>>;
foreach<U>(f: (value: A) => U): void;
getOrElse(or: () => A): A;
getOrElseValue(or: A): A;
forall(p: (value: A) => boolean): boolean;
exists(p: (value: A) => boolean): boolean;
flatMap<A1, B1 extends B>(f: (value: A) => Either<A1, B1>): Either<A1, B1>;
map<A1>(f: (value: A) => A1): Either<A1, B>;
filterToOption(p: (value: A) => boolean): Option<Either<A, B>>;
get toCollection(): Collection<A>;
get toOption(): Option<A>;
}
}
export declare function right<T>(value: T): Right<T>;
export declare function left<E>(value: E): Left<E>;