Skip to main content

Class: SubscribableMapFunctions

Utility class for generating common functions for mapping subscribables.

Constructors

constructor

new SubscribableMapFunctions(): SubscribableMapFunctions

Returns

SubscribableMapFunctions

Methods

abs

abs<T>(): (input: T, currentVal?: T) => number

Generates a function which maps an input number to its absolute value.

Type parameters

NameType
Textends number

Returns

fn

A function which maps an input number to its absolute value.

▸ (input, currentVal?): number

Parameters
NameType
inputT
currentVal?T
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:76


and

and(): (input: readonly boolean[], currentVal?: boolean) => boolean

Generates a function which maps an input boolean tuple to true if all tuple members are true and to false otherwise. A zero-length tuple is mapped to false.

Returns

fn

A function which maps an input boolean tuple to true if all tuple members are true and to false otherwise.

▸ (input, currentVal?): boolean

Parameters
NameType
inputreadonly boolean[]
currentVal?boolean
Returns

boolean

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:50


atFrequency

atFrequency<T>(freq, timeFunc?): (input: T, currentVal?: T) => T

Generates a function which maps an input number to itself up to a maximum frequency, and to the previous mapped value otherwise. In other words, the mapping function will not pass through changes in the input value if not enough time has elapsed since the last change that was passed through.

Caution: The mapping function can only pass through the input value when the input value changes. This means that if the mapping function rejects a change in the input value due to the maximum frequency being exceeded, it is possible that particular input value will never be reflected in the mapped value, even after the frequency cutoff has expired. For example, if the input value changes from a to b but is rejected by the mapping function and subsequently remains b forever, then the mapped value will remain a forever.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
freqnumber | Subscribable<number>undefinedThe maximum frequency at which to map the input to itself, in hertz.
timeFunc() => numberDate.nowA function which gets the current time in milliseconds. Defaults to Date.now().

Returns

fn

A function which maps an input number to itself up to the specified maximum frequency, and to the previous mapped value otherwise.

▸ (input, currentVal?): T

Parameters
NameType
inputT
currentVal?T
Returns

T

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:199


changedBy

changedBy<T>(threshold): (input: T, currentVal?: T) => number

Generates a function which maps an input number to itself if and only if it differs from the previous mapped value by a certain amount, and to the previous mapped value otherwise.

Type parameters

NameType
Textends number

Parameters

NameTypeDescription
thresholdnumber | Subscribable<number>The minimum difference between the input and the previous mapped value required to map the input to itself.

Returns

fn

A function which maps an input number to itself if and only if it differs from the previous mapped value by the specified amount, and to the previous mapped value otherwise.

▸ (input, currentVal?): number

Parameters
NameType
inputT
currentVal?T
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:178


count

count<T>(predicate): (input: readonly T[], currentVal?: number) => number

Generates a function which maps an input tuple to a count of the number of items in the tuple that satisfy a given condition.

Type parameters

Name
T

Parameters

NameTypeDescription
predicate(value: T) => booleanA function which evaluates whether an item should be counted.

Returns

fn

A function which maps an input tuple to a count of the number of items in the tuple that satisfy the condition specified by the predicate.

▸ (input, currentVal?): number

Parameters
NameType
inputreadonly T[]
currentVal?number
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:105


identity

identity<T>(): (input: T) => T

Generates a function which maps an input to itself.

Type parameters

Name
T

Returns

fn

A function which maps an input to itself.

▸ (input): T

Parameters
NameType
inputT
Returns

T

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:12


max

max(): (input: readonly number[], currentVal?: number) => number

Generates a function which maps an input number tuple to the maximum numeric value contained in the tuple. A zero-length tuple is mapped to -Infinity.

Returns

fn

A function which maps an input number tuple to the maximum numeric value contained in the tuple.

▸ (input, currentVal?): number

Parameters
NameType
inputreadonly number[]
currentVal?number
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:94


min

min(): (input: readonly number[], currentVal?: number) => number

Generates a function which maps an input number tuple to the minimum numeric value contained in the tuple. A zero-length tuple is mapped to Infinity.

Returns

fn

A function which maps an input number tuple to the minimum numeric value contained in the tuple.

▸ (input, currentVal?): number

Parameters
NameType
inputreadonly number[]
currentVal?number
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:85


nand

nand(): (input: readonly boolean[], currentVal?: boolean) => boolean

Generates a function which maps an input boolean tuple to false if all tuple members are true and to false otherwise. A zero-length tuple is mapped to true.

Returns

fn

A function which maps an input boolean tuple to true if all tuple members are true and to false otherwise.

▸ (input, currentVal?): boolean

Parameters
NameType
inputreadonly boolean[]
currentVal?boolean
Returns

boolean

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:60


negate

negate<T>(): (input: T, currentVal?: T) => number

Generates a function which maps an input number to its negation.

Type parameters

NameType
Textends number

Returns

fn

A function which maps an input number to its negation.

▸ (input, currentVal?): number

Parameters
NameType
inputT
currentVal?T
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:68


nor

nor(): (input: readonly boolean[], currentVal?: boolean) => boolean

Generates a function which maps an input boolean tuple to true if no tuple member is true and to false otherwise. A zero-length tuple is mapped to true.

Returns

fn

A function which maps an input boolean tuple to true if no tuple member is true or there are no tuple members, and to false otherwise.

▸ (input, currentVal?): boolean

Parameters
NameType
inputreadonly boolean[]
currentVal?boolean
Returns

boolean

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:40


not

not<T>(): (input: T, currentVal?: T) => boolean

Generates a function which maps an input boolean to its negation.

Type parameters

NameType
Textends boolean

Returns

fn

A function which maps an input boolean to its negation.

▸ (input, currentVal?): boolean

Parameters
NameType
inputT
currentVal?T
Returns

boolean

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:20


or

or(): (input: readonly boolean[], currentVal?: boolean) => boolean

Generates a function which maps an input boolean tuple to true if at least one tuple member is true and to false otherwise. A zero-length tuple is mapped to false.

Returns

fn

A function which maps an input boolean tuple to true if at least one tuple member is true and to false otherwise.

▸ (input, currentVal?): boolean

Parameters
NameType
inputreadonly boolean[]
currentVal?boolean
Returns

boolean

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:30


reduce

reduce<T>(callbackFn, initialValue?): (input: readonly T[], currentVal?: T) => T

Generates a function which maps an input tuple to an arbitrary accumulated value by calling a specified function for each input in the tuple in order. The return value of the callback function is the accumulated value and is provided as an argument in the next call to the callback function. The accumulated value provided as an argument to the first call to the callback function is equal to the first input in the tuple. The value returned by the last invocation of the callback function is the final mapped value.

Type parameters

Name
T

Parameters

NameTypeDescription
callbackFn(previousValue: T, currentInput: T, currentIndex: number, inputs: readonly T[]) => TA callback function that returns an accumulated value after being called for each input.
initialValue?T-

Returns

fn

A function which maps an input tuple to an arbitrary accumulated value by calling the specified function for each input in the tuple in order.

▸ (input, currentVal?): T

Parameters
NameType
inputreadonly T[]
currentVal?T
Returns

T

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:127

reduce<T, U>(callbackFn, initialValue): (input: readonly T[], currentVal?: U) => U

Generates a function which maps an input tuple to an arbitrary accumulated value by calling a specified function for each input in the tuple in order. The return value of the callback function is the accumulated value and is provided as an argument in the next call to the callback function. The value returned by the last invocation of the callback function is the final mapped value.

Type parameters

Name
T
U

Parameters

NameTypeDescription
callbackFn(previousValue: U, currentInput: T, currentIndex: number, inputs: readonly T[]) => UA callback function that returns an accumulated value after being called for each input.
initialValueUThe initial accumulated value to provide as an argument to the first call to the callback function.

Returns

fn

A function which maps an input tuple to an arbitrary accumulated value by calling the specified function for each input in the tuple in order.

▸ (input, currentVal?): U

Parameters
NameType
inputreadonly T[]
currentVal?U
Returns

U

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:142


withPrecision

withPrecision<T>(precision): (input: T, currentVal?: T) => number

Generates a function which maps an input number to a rounded version of itself at a certain precision.

Type parameters

NameType
Textends number

Parameters

NameTypeDescription
precisionnumber | Subscribable<number>The precision to which to round the input.

Returns

fn

A function which maps an input number to a rounded version of itself at the specified precision.

▸ (input, currentVal?): number

Parameters
NameType
inputT
currentVal?T
Returns

number

Defined in

src/sdk/sub/SubscribableMapFunctions.ts:159