UNPKG

r3bl-ts-utils

Version:

The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu

72 lines (71 loc) 3.1 kB
export declare type ReceiverFn<T> = (it: T) => void; export declare type ReceiverFnWithReturn<T, R> = (it: T) => R; export declare type ReceiverFnAsync<T, R> = (it: T) => Promise<R>; /** * @param contextObject value of `it` * @param receiverFns array of lambdas that accepts `it` * @return contextObject that is passed */ export declare const _then: <T>(contextObject: T, ...receiverFns: ReceiverFn<T>[]) => T; /** * @param contextObject value of `it` * @param receiverFn lambda that accepts `it` * @return contextObject that is passed */ export declare const _also: <T>(contextObject: T, receiverFn: ReceiverFn<T>) => T; /** * @param contextObject value of `it` * @param receiverFn lambda that accepts deep copy of `it` * @return deep copy of `it` */ export declare const _alsoSafe: <T>(contextObject: T, receiverFn: ReceiverFn<T>) => T; /** * @param contextObject value of `it` * @param receiverFn lambda that accepts `it` * @return {contextObject that is passed, promise returned by receiverFn} */ export declare const _alsoAsync: <T, R>(contextObject: T, receiverFn: ReceiverFnAsync<T, R>) => { contextObject: T; promiseFromReceiverFn: Promise<R>; }; /** * @param contextObject value of `it` * @param receiverFn lambda that accepts deep copy of `it` * @return {contextObjectDeepCopy deep copy of `it`, promise returned by receiverFn} */ export declare const _alsoSafeAsync: <T, R>(contextObject: T, receiverFn: ReceiverFnAsync<T, R>) => { contextObjectDeepCopy: T; promiseFromReceiverFn: Promise<R>; }; /** * @param contextObject value of `it` * @param receiverFnWithReturn lambda that accepts `it` * @return result of the receiverFnWithReturn (lambda) */ export declare const _let: <T, R>(contextObject: T, receiverFnWithReturn: ReceiverFnWithReturn<T, R>) => R; /** * @param contextObject value of `it` * @param receiverFnWithReturn lambda that accepts deep copy of `it` * @return result of the receiverFnWithReturn (lambda) */ export declare const _letSafe: <T, R>(contextObject: T, receiverFnWithReturn: ReceiverFnWithReturn<T, R>) => R; export interface ImplicitReceiverObject<T> { fnWithReboundThis: (this: T) => void; } export interface ImplicitReceiverObjectWithReturn<T, R> { fnWithReboundThis: (this: T) => R; } /** * @param contextObject value of `this` (in the `blockWithReboundThis` function) * @param objectContainingFnWithReboundThis object containing function `blockWithReboundThis` * which accepts contextObject (aka `this`) * @return contextObject that is passed */ export declare const _apply: <T>(contextObject: T, objectContainingFnWithReboundThis: ImplicitReceiverObject<T>) => T; /** * @param contextObject value of `this` (in the `blockWithReboundThis` function) * @param objectContainingFnWithReboundThis object containing function `blockWithReboundThis` * which accepts contextObject (aka `this`) * @return result of the `blockWithReboundThis` function */ export declare const _with: <T, R>(contextObject: T, objectContainingFnWithReboundThis: ImplicitReceiverObjectWithReturn<T, R>) => R;