API Reference

Here are some of interfaces provided in the library. Full API reference will be available later.

Option[T] class for managing empty and fulfilled data easily.

declare class Option<T> implements Optionable<T> {
    static Some<T>(value: T): Option<T>;
    static None(): Option<{}>;
    
    isEmpty: boolean;
    isDefined: boolean;
    
    constructor(value?: T);
    
    getOrElse<V>(stopGap: V): T | V;
    orElse<V>(fallback: Option<V>): Option<T | V>;
    
    map<P>(func: (val: T) => P): Option<P | T>;
    flatMap<P>(func: (val: T) => Option<P>): Option<T | P>;
    coflatMap<P>(func: (val: Option<T>) => P): Option<T | P>;
    forEach(func: (val: T) => void): void;
    filter(pred: (val: T) => boolean): Option<T>;
    flatten<K>(): Option<T | K>;
    combine<P>(that: Option<P>): Option<T | P>;
    fold<S>(f: (val: T) => S, g: () => S): S;
    exists(pred: (val: T) => boolean): boolean;
    forall(pred: (val: T) => boolean): boolean;
}

Either[K, T] class for managing right/wrong data or data disjunctions.

declare class Either<K, T> implements Validatable<K, T> {
    static Left<T>(val: T): Either<T, void>;
    static Right<T>(val: T): Either<void, T>;
    
    isLeft: boolean;
    isRight: boolean;
    
    constructor(left?: K, right?: T);
    
    left(): LProjection<K, T>;
    right(): RProjection<K, T>;
    getOrElse<P>(stopGap: P): T | P;
    swap(): Either<T, K>;
    joinLeft<S = K, P = T>(): Either<S, P>;
    joinRight<S = K, P = T>(): Either<S, P>;
    fold<S>(f: (val: T) => S, g: (val: K) => S): S;
    exists(pred: (val: T) => boolean): boolean;
    forall(pred: (val: T) => boolean): boolean;
}
interface Projection<T> {
    getOrElse<P>(val: P): T | P;
    get(): T | never;
    toOption(): Option<T>;
} 

Try[T] class for easy working with throwable functions and data they produce.

interface Try<T> {
    isFailure: boolean;
    isSuccess: boolean;
    
    toEither(): Either<Error, T>;
    toOption(): Option<T>;
    
    getOrElse<U>(stopGap: U): U | T;
    get(): T | never;
    orElse<U>(fallback: Try<U>): Try<T | U>;
    
    map<P>(func: (val: T) => P): Try<P | T>;
    flatMap<P>(func: (val: T) => Try<P>): Try<T | P>;
    forEach(func: (val: T) => void): void;
    filter(pred: (val: T) => boolean): Try<T>;
    fold<S>(f: (val: T) => S, g: (val: Error) => S): S;
     
    transform<S>(f: (val: T) => Try<S>, g: (err: Error) => Try<S>): Try<S>;
    recover<S>(f: (err: Error) => S): Try<S | T>;
    recoverWith<S>(f: (err: Error) => Try<S>): Try<S | T>;
    failed(): Try<Error>;
    product<P>(next: Try<P>): Try<[T, P]>;
    exists(pred: (val: T) => boolean): boolean;
    forall(pred: (val: T) => boolean): boolean;
}

Last updated