0.4.3Array convenience functions
Extends AtpObject
Partitions the elements of an array into separate arrays based on a partition function.
(Function)
A function that will be applied to each element in the array.
Object:
a([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
.partition(n => n % 3) ==
{
0: [3, 6, 9],
1: [1, 4, 7, 10],
2: [2, 5, 8]
}
Wraps an array in an ATPArray
(Array)
Syntactic sugar functions for Objects
(any)
Funcional-style assignment: Takes the result of an expression and passes it to the given function, returning the function's result.
(Any)
Any:
o(1 + 2).as(sum => sum * 3) == 9
Merges two objects. By default, objects are merged recursively and arrays are concatenated. This behavior can be altered by sending the appropriate flags. Other values in the original object are replaced by the corresponding values in the second object.
(Object)
The object to merge with
(Bitfield
= mergeFlags.RECURSIVE|mergeFlags.CONCAT_ARRAYS)
AtpObject:
The merged object
A functional switch statement. The value of the switch statement will be the return value of whichever action is run.
(Object)
Actions should be an object whose keys are the possible values of the switch variable
and whose values are functions that return the desired final value.
Actions may optionally include a 'default' function that will run if no other values are met
Any:
const mode = "json";
o(mode).switch({
html: () => "<h1>Hello World!</h1>",
json: () => ({msg: "Hello World!}),
default: () => "Invalid format"
}) == {msg: "Hello World!}
Wrap the given object to make the syntactic sugar functionas available
(any)
Convenience wrapper around setTimeout
(Function)
the function to delay
f(func).delay().for(5).seconds();
Cancel the delayed function. Note that the DelayedEvent can be re-queued by calling runIn() again.
DelayedEvent:
Synonym for runIn, useful in fluent expressions
(Number)
The time to delay the function's execution, modifiable with subsequent interval calls
DelayedEvent:
f(func).delay().for(5).seconds();
Set (or reset) the delay of the function
(Number)
The time to delay the function's execution, modifiable with subsequent interval calls
DelayedEvent:
f(func).delay().for(5).seconds();
Interpret the previously specified delay as a delay in milliseconds
DelayedEvent:
f(func).delay().for(5).milliseconds();
Interpret the previously specified delay as a delay in seconds
DelayedEvent:
f(func).delay().for(5).seconds();
Interpret the previously specified delay as a delay in minutes
DelayedEvent:
f(func).delay().for(5).minutes();
Interpret the previously specified delay as a delay in hours
DelayedEvent:
f(func).delay().for(5).hours();
Interpret the previously specified delay as a delay in days
DelayedEvent:
f(func).delay().for(5).days();
A wrapper for convenient functions related to functions
Convenience method for setTimeout() allowing for a more fluid style
DelayedEvent:
f(func).delay().for(5).seconds();
Wrap the specified function in an ATPFunction object
(Function)