scats
Version:
Useful scala classes in typescript
56 lines (55 loc) • 2.24 kB
TypeScript
import { Collection } from './collection.js';
import { Either } from './either.js';
import { ArrayIterable } from './array-iterable.js';
import { HashSet } from './hashset.js';
import { HashMap } from './hashmap.js';
import { Mappable } from './mappable.js';
export interface OptionMatch<A, T> {
some: (value: A) => T;
none: () => T;
}
export declare abstract class Option<A> extends ArrayIterable<A, Option<A>> implements Mappable<A> {
abstract readonly get: A;
static when<A>(cond: boolean): (a: () => A) => Option<A>;
static useless<A>(cond: boolean): (a: () => A) => Option<A>;
protected fromArray(array: A[]): Option<A>;
exists(p: (value: A) => boolean): boolean;
filter(p: (value: A) => boolean): Option<A>;
filterNot(p: (value: A) => boolean): Option<A>;
map<B>(f: (item: A) => B): Option<B>;
flatMap<B>(p: (value: A) => Option<B>): Option<B>;
mapPromise<B>(f: (v: A) => Promise<B>): Promise<Option<B>>;
flatMapPromise<B>(f: (item: A) => Promise<Mappable<B>>): Promise<Mappable<B>>;
foldValue<B>(ifEmpty: () => B): (f: (_: A) => B) => B;
forall(p: (_: A) => boolean): boolean;
foreach(f: (_: A) => void): void;
getOrElse(f: () => A): A;
getOrElseValue(other: A): A;
getOrElseThrow(error: () => Error): A;
contains<A1 extends A>(x: A1): boolean;
get isDefined(): boolean;
orElse(alternative: () => Option<A>): Option<A>;
orElseValue(alternative: Option<A>): Option<A>;
get orNull(): A | null;
get orUndefined(): A | undefined;
get toCollection(): Collection<A>;
toRight<X>(left: () => X): Either<X, A>;
toLeft<X>(right: () => X): Either<A, X>;
get toArray(): A[];
get toSet(): HashSet<A>;
match<T>(matcher: OptionMatch<A, T>): T;
toMap<K, V>(mapper: (item: A) => [K, V]): HashMap<K, V>;
}
export declare class Some<A> extends Option<A> {
private readonly value;
constructor(value: A);
get get(): A;
get isEmpty(): boolean;
}
export declare class None<A> extends Option<A> {
get get(): A;
get isEmpty(): boolean;
}
export declare function option<A>(value: A | null | undefined): Option<A>;
export declare function some<A>(value: A): Some<A>;
export declare const none: Option<any>;