declare module lib_call { /** * @desc hacked class for postfix function application * @author fenris */ class class_valuewrapper { /** * @author fenris */ protected value: type_value; /** * @desc [constructor] * @author fenris */ constructor(value: type_value); /** * @desc [accessor] applies a function and returns a new valuewrapper * @author fenris */ pass(function_: (value: type_value) => type_value_): class_valuewrapper; /** * @desc [accessor] gives the wrapped value * @author fenris */ extract(): type_value; } /** * @desc shortcut for constructing a valuewrapper-object * @author fenris */ function vw(value: type_value): class_valuewrapper; /** * @author fenris */ function use(input: type_input, function_: (input: type_input) => type_output): type_output; /** * @desc just the identity; useful for some callbacks etc. * @author fenris */ function id(x: type_value): type_value; /** * @desc composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) * @param {function} function_f * @param {function} function_g * @author fenris */ function compose(function_f: (type_x: any) => type_y, function_g: (type_y: any) => type_z): (value: type_x) => type_z; /** * @desc transforms a function with sequential input into a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) * @param {function} f * @param {int} n (don't set manually) * @return {function} the currified version of the in put function * @author fenris */ function curryfy(f: Function, n?: int): Function; } declare module lib_call { /** * @author fenris */ type type_executor = ((resolve: (result?: type_result) => any, reject?: (reason?: type_reason) => void) => void); /** * @author fenris */ function executor_resolve(result: type_result): type_executor; /** * @author fenris */ function executor_reject(reason: type_reason): type_executor; /** * @author fenris */ function executor_transform(executor: type_executor, transform_result: (result_from: type_result_from) => type_result_to, transform_reason: (error_from: type_error_from) => type_error_to): type_executor; /** * @author fenris */ function executor_transform_default(executor: type_executor, transform_result: (result_from: type_result_from) => type_result_to, wrap_string?: string): type_executor; /** * @author fenris */ function executor_compose_sequential(first: type_executor, second: (result: type_result_first) => type_executor): type_executor; /** * @author fenris */ function executor_chain(state: type_state, executors: Array<(state: type_state) => type_executor>): type_executor; /** * @author fenris */ function executor_first(executors: Array>): type_executor>; /** * @author fenris */ function executor_condense(executors: Array>): type_executor, Error>; /** * @author fenris * @deprecated use condense */ function executor_filter(executors: Array>, predicate: (element: type_element) => boolean): type_executor, Error>; /** * @author fenris * @deprecated use condense */ function executor_map(executors: Array>, transformator: (element1: type_element1) => type_element2): type_executor, Error>; /** * @author fenris * @deprecated use condense */ function executor_reduce(executors: Array>, initial: type_result, accumulator: (result: type_result, element: type_element) => type_result): type_executor; } declare module lib_call { /** * @author fenris */ type type_promise = Promise; /** * @author fenris */ function promise_reject(reason: type_reason): type_promise; /** * @author fenris */ function promise_resolve(result: type_result): type_promise; /** * @author fenris */ function promise_make(executor: (resolve: (result?: type_result) => void, reject: (reason?: type_reason) => void) => void): type_promise; /** * @author fenris */ function promise_then_close(promise: type_promise, resolver: (result: type_result) => void, rejector: (reason: type_reason) => void): void; /** * @author fenris */ function promise_then_append(promise: type_promise, resolver: (result: type_result) => type_promise, rejector?: (reason: type_reason) => type_promise): type_promise; /** * @author fenris */ function promise_all(promises: Array>): type_promise, type_reason>; /** * @author fenris */ function promise_chain(promises: Array<(input: type_result) => type_promise>, start?: type_result): type_promise; /** * @author fenris */ function promise_condense(promises: Array<() => type_promise>): type_promise, type_reason>; /** * @author fenris */ function promise_group(promises: { [name: string]: () => type_promise; }, serial?: boolean): type_promise<{ [name: string]: any; }, type_reason>; /** * @author fenris */ function promise_wrap(promise: type_promise, transformator_result: (reason: type_result_inner) => type_result_outer, transformator_reason?: (reason: type_reason) => type_reason): Promise; /** * @author fenris */ function promise_show(label: string): (result: type_result) => type_promise; /** * @author fenris */ function promise_log(result: type_result): (result: type_result) => type_promise; /** * @author fenris */ function promise_attach(state: { [name: string]: any; }, promise: type_promise, name: string): type_promise<{ [name: string]: any; }, type_reason>; /** * @author fenris */ function promise_delay(promise: type_promise, delay: int): Promise; /** * @author fenris */ function promise_to_executor(promise: type_promise): type_executor; } declare module lib_call { /** * @author fenris */ type type_initializer_state = int; const initializer_state_initial: type_initializer_state; const initializer_state_waiting: type_initializer_state; const initializer_state_successful: type_initializer_state; const initializer_state_failed: type_initializer_state; /** * @author fenris */ type type_initializer = { fetcher: () => type_promise; state?: type_initializer_state; queue: Array<{ resolve: (result?: type_result) => void; reject: (reason?: type_reason) => void; }>; result?: type_result; reason?: type_reason; }; /** * @author fenris */ function initializer_make(fetcher: () => type_promise): type_initializer; /** * @author fenris */ function initializer_reset(subject: type_initializer): void; /** * @author fenris */ function initializer_state(subject: type_initializer): type_initializer_state; /** * @author fenris */ function initializer_get(subject: type_initializer): type_promise; } declare module lib_call { /** * @author fenris */ type type_deferral = { representation: (input: type_input) => Promise; }; /** * @author fenris * @desc activates the deferral and handles its output according to a given procedure * @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument */ function deferral_use(deferral: type_deferral, input: type_input, procedure: (output: type_output) => void): void; /** * @author fenris * @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject") */ function deferral_make(handler: (input: type_input, convey: (output: type_output) => void) => void): type_deferral; /** * @author fenris * @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject") */ function deferral_wrap(function_: (input: type_input) => type_output): type_deferral; /** * @author fenris */ function deferral_id(): type_deferral; /** * @author fenris */ function deferral_const(value: type_value): type_deferral; /** * @author fenris */ function deferral_delay(output: type_output, delay: int): type_deferral; /** * @author fenris * @desc connects two deferrals to form a new one; the output of the first is taken as input for the second * (similar to "Promise.then" when passing a function which returns a new promise) * @param {type_deferral} first a simple deferral * @param {(value1 : type_value1)=>type_deferral} second a function depending from a value returning a deferral */ function deferral_compose_serial(first: type_deferral, second: type_deferral): type_deferral; /** * @author fenris */ function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }: { left: type_deferral; right: type_deferral; }): type_deferral; /** * @author fenris * @desc repeatedly applied serial composition */ function deferral_chain(members: Array>): type_deferral; /** * @author fenris */ } declare module lib_call { /** * @author fenris */ class class_deferral { /** * @author fenris */ private subject; /** * @author fenris */ private constructor(); /** * @author fenris */ private static _cram; /** * @author fenris */ private static _tear; /** * @author fenris */ static make(handler: (input: type_input, convey: (value: type_output) => void) => void): class_deferral; /** * @author fenris */ use(input: type_input, procedure: (value: type_output) => void): void; /** * @author fenris */ compose_serial(second: class_deferral): class_deferral; /** * @author fenris */ static chain(members: Array>): class_deferral; /** * @author fenris */ static wrap(function_: (input: type_input) => type_output): class_deferral; /** * @author fenris */ static const_(value: type_value): class_deferral; /** * @author fenris */ static delay(output: type_output, delay: int): class_deferral; } } declare module lib_call { /** * @author fenris */ function timeout(function_: () => void, delay: int): int; /** * @desc a definition for a value being "defined" * @author neuc */ function is_def(obj: type_value, null_is_valid?: boolean): boolean; /** * @desc returns the value if set and, when a type is specified, if the type is correct, if not return default_value * @author neuc */ function def_val(value: any, default_value: any, type?: string, null_is_valid?: boolean): any; /** * @desc just the empty function; useful for some callbacks etc. * @author fenris */ function nothing(): void; /** * @desc outputs * @author fenris */ function output(...args: Array): void; /** * @desc converts the "arguments"-map into an array * @param {Object} args * @author fenris */ function args2list(args: any): Array; /** * @desc provides the call for an attribute of a class as a regular function * @param {string} name the name of the attribute * @return {*} * @author fenris */ function attribute(name: string): (object: type_object) => type_attribute; /** * @desc provides a method of a class as a regular function * @param {string} name the name of the method * @return {function} * @author fenris */ function method(name: string): (object: type_object) => type_output; /** * @author fenris */ type type_unival = { kind: string; data?: any; }; /** * @author fenris */ function distinguish(unival: type_unival, handlers: { [kind: string]: (data?: any) => any; }, fallback?: (unival?: type_unival) => any): any; }