Powerglove
npm install powerglove
API
pipe
[(a -> *)] -> a -> Promise -> *
Passes a value through an array of functions sequentially; Returns value fulfilled from final function in the array.
Example:
void async { const weirdMath = await // -> 42 }
Params:
Type | Name | Description |
---|---|---|
Function[] |
funcs | Array of functions |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills with value returned by last index of func |
all
[(a -> *)] -> a -> Promise -> [*]
Executes an array of functions concurrently; returns an array of fulfilled values.
Example:
void async { const sayHi = await // -> [ 'Hello, world!', '¡Hola, world!', 'Bonjour, world!' ] }
Params:
Type | Name | Description |
---|---|---|
Function[] |
funcs | Array of functions |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills with an array of values returned from each function in funcs |
race
[(a -> *)] -> a -> Promise -> *
Executes an array of functions concurrently; Returns value of first function to resolve.
Example:
void async { const fast = ` Speed Racer` const faster = ` Racer X` const fastest = ` Chim Chim` const announceWinner = await // -> `And the winner is... Chim Chim!` }
Params:
Type | Name | Description |
---|---|---|
Function[] |
funcs | Array of functions |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills with value of first function in funcs to resolve |
until
(a -> Bool) -> (a -> *) -> a -> Promise -> *
Executes function until done
returns true
. The return value of
the repeating function is passed into itself on each successive iteration.
Example:
void async { const minusminus = x - 1 const smallEnough = x <= 0 const subtractAll = minusminus await // -> 0 const plusplus = x + 1 const largeEnough = x >= 100000 const addALot = plusplus await // -> 100000 }
Params:
Type | Name | Description |
---|---|---|
Function |
done | Accepts value returned by f . f is called repeatedly until this function returns true |
Function |
f | Function to be called repeatedly. Passes its own return value into itself on each iteration |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills result of f after n recursive calls |
when
(a -> Bool) -> (a -> *) -> (a -> *) -> a -> Promise -> *
Tests a value and passes value to either the pass
function or the fail
function
Example:
void async { const over9000 = lvl > 9000 const praise = `Holy crap! ?! THAT'S OVER 9000!` const insult = `Pffft. ? Is that all you got???` const analyzePowerLevel = praiseinsult await // -> `Holy crap! 9001?! THAT'S OVER 9000!` await // -> `Pffft. 1? Is that all you got???` }
Params:
Type | Name | Default | Description |
---|---|---|---|
Function |
test | Accepts x ; returns true or false |
|
Function |
pass | Called with x if test returns true |
|
Function |
fail | a => a |
Called with x if test returns false |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills with value returned by pass or fail |
delay
Number -> (a -> *) -> a -> Promise -> *
Accepts ms
, number of milliseconds to wait, before executing function f
.
Example:
void async { const timeSince = Date - ms await // -> ~300ms }
Params:
Type | Name | Description |
---|---|---|
Number |
funcs | Array of functions |
Function |
f | Function to be called after timeout |
* |
x | Any value |
Return:
Type | Description |
---|---|
Promise |
Fulfills with value returned by f(x) |