Class: SubscribableMapFunctions
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:9
Utility class for generating common functions for mapping subscribables.
Constructors
Constructor
new SubscribableMapFunctions():
SubscribableMapFunctions
Returns
SubscribableMapFunctions
Methods
abs()
static
abs<T
>(): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:78
Generates a function which maps an input number to its absolute value.
Type Parameters
Type Parameter |
---|
T extends number |
Returns
A function which maps an input number to its absolute value.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
number
and()
static
and(): (input
,currentVal?
) =>boolean
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:52
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
A function which maps an input boolean tuple to true
if all tuple members are true
and to false
otherwise.
(
input
,currentVal?
):boolean
Parameters
Parameter | Type |
---|---|
input | readonly boolean [] |
currentVal? | boolean |
Returns
boolean
atFrequency()
static
atFrequency<T
>(freq
,timeFunc
): (input
,currentVal?
) =>T
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:341
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
Type Parameter |
---|
T |
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
freq | number | Subscribable <number > | undefined | The maximum frequency at which to map the input to itself, in hertz. |
timeFunc | () => number | Date.now | A function which gets the current time in milliseconds. Defaults to Date.now() . |
Returns
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
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
T
average()
static
average(): (inputs
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:134
Generates a function which maps an input number tuple to the average numeric value contained in the tuple. A zero-length tuple is mapped to NaN.
Returns
A function which maps an input number tuple to the average numeric value contained in the tuple.
(
inputs
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
inputs | readonly number [] |
currentVal? | number |
Returns
number
changedBy()
static
changedBy<T
>(threshold
): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:320
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
Type Parameter |
---|
T extends number |
Parameters
Parameter | Type | Description |
---|---|---|
threshold | number | Subscribable <number > | The minimum difference between the input and the previous mapped value required to map the input to itself. |
Returns
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
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
number
count()
static
count<T
>(predicate
): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:107
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
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | (value ) => boolean | A function which evaluates whether an item should be counted. |
Returns
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
Parameter | Type |
---|---|
input | readonly T [] |
currentVal? | number |
Returns
number
identity()
static
identity<T
>(): (input
) =>T
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:14
Generates a function which maps an input to itself.
Type Parameters
Type Parameter |
---|
T |
Returns
A function which maps an input to itself.
(
input
):T
Parameters
Parameter | Type |
---|---|
input | T |
Returns
T
max()
static
max(): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:96
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
A function which maps an input number tuple to the maximum numeric value contained in the tuple.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | readonly number [] |
currentVal? | number |
Returns
number
min()
static
min(): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:87
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
A function which maps an input number tuple to the minimum numeric value contained in the tuple.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | readonly number [] |
currentVal? | number |
Returns
number
nand()
static
nand(): (input
,currentVal?
) =>boolean
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:62
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
A function which maps an input boolean tuple to true
if all tuple members are true
and to false
otherwise.
(
input
,currentVal?
):boolean
Parameters
Parameter | Type |
---|---|
input | readonly boolean [] |
currentVal? | boolean |
Returns
boolean
negate()
static
negate<T
>(): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:70
Generates a function which maps an input number to its negation.
Type Parameters
Type Parameter |
---|
T extends number |
Returns
A function which maps an input number to its negation.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
number
nor()
static
nor(): (input
,currentVal?
) =>boolean
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:42
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
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
Parameter | Type |
---|---|
input | readonly boolean [] |
currentVal? | boolean |
Returns
boolean
not()
static
not<T
>(): (input
,currentVal?
) =>boolean
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:22
Generates a function which maps an input boolean to its negation.
Type Parameters
Type Parameter |
---|
T extends boolean |
Returns
A function which maps an input boolean to its negation.
(
input
,currentVal?
):boolean
Parameters
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
boolean
or()
static
or(): (input
,currentVal?
) =>boolean
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:32
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
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
Parameter | Type |
---|---|
input | readonly boolean [] |
currentVal? | boolean |
Returns
boolean
reduce()
Call Signature
static
reduce<T
>(callbackFn
,initialValue?
): (input
,currentVal?
) =>T
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:156
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
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
callbackFn | (previousValue , currentInput , currentIndex , inputs ) => T | A callback function that returns an accumulated value after being called for each input. |
initialValue? | T | - |
Returns
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
Parameter | Type |
---|---|
input | readonly T [] |
currentVal? | T |
Returns
T
Call Signature
static
reduce<T
,U
>(callbackFn
,initialValue
): (input
,currentVal?
) =>U
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:171
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
Type Parameter |
---|
T |
U |
Parameters
Parameter | Type | Description |
---|---|---|
callbackFn | (previousValue , currentInput , currentIndex , inputs ) => U | A callback function that returns an accumulated value after being called for each input. |
initialValue | U | The initial accumulated value to provide as an argument to the first call to the callback function. |
Returns
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
Parameter | Type |
---|---|
input | readonly T [] |
currentVal? | U |
Returns
U
sum()
static
sum(): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:123
Generates a function which maps an input tuple to the sum of the numeric items contained in the tuple.
Returns
A function which maps an input tuple to the sum of the numeric items contained in the tuple.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | readonly number [] |
currentVal? | number |
Returns
number
withPrecision()
static
withPrecision<T
>(precision
,round
): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:191
Generates a function which maps an input number to a rounded version of itself at a certain precision.
Type Parameters
Type Parameter |
---|
T extends number |
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
precision | number | Accessible <number > | undefined | The precision to which to round the input. If the precision is defined as an Accessible , then changes in the precision value will not be reflected in the mapped output until the next time the value of the input number changes. |
round | Rounding | Rounding.Nearest | The rounding behavior to use. Defaults to Rounding.Nearest . |
Returns
A function which maps an input number to a rounded version of itself at the specified precision.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
number
withPrecisionHysteresis()
static
withPrecisionHysteresis<T
>(precision
,hysteresis
,round
): (input
,currentVal?
) =>number
Defined in: src/sdk/sub/SubscribableMapFunctions.ts:225
Generates a function which maps an input number to a rounded version of itself at a certain precision with hysteresis applied.
When a previously mapped value exists, any new input value (x
) is compared to the previously mapped value
(y0
). Define x1
as the least input value that can be rounded to y0
and x2
as the greatest input value that
can be rounded to y0
. Then x
is mapped to a new rounded output value if and only if x < x1 - h1
or
x > x2 + h2
, where h1
and h2
are the lower and upper hysteresis values, respectively. Otherwise, x
is
mapped to y0
.
Type Parameters
Type Parameter |
---|
T extends number |
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
precision | number | undefined | The precision to which to round the input. |
hysteresis | number | readonly [number , number ] | undefined | The hysteresis to apply to the mapping function. If defined as a [number, number] tuple, then the first number in the tuple is taken as the lower hysteresis and second number as the upper hysteresis. If defined as a single number, then that is taken as both the lower and upper hysteresis. Negative values are clamped to zero. |
round | Rounding | Rounding.Nearest | The rounding behavior to use. Defaults to Rounding.Nearest . |
Returns
A function which maps an input number to a rounded version of itself at the specified precision and with the specified hysteresis.
(
input
,currentVal?
):number
Parameters
Parameter | Type |
---|---|
input | T |
currentVal? | T |
Returns
number