New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

powerglove

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

powerglove

Async generator-based control flow

  • 0.7.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm version build status dependency status devdependency status Coverage Status

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:

import { pipe } from 'powerglove'

void async () => {

  const weirdMath = pipe([
    n => n / 1,
    n => n + 4,
    n => n * 7
  ])

  await weirdMath(2)
  // -> 42

}()

Params:

TypeNameDescription
Function[]funcsArray of functions
*xAny value

Return:

TypeDescription
PromiseFulfills 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:

import { all } from 'powerglove'

void async () => {

  const sayHi = all([
    x => `Hello, ${x}!`,
    x => `¡Hola, ${x}!`,
    x => `Bonjour, ${x}!`
  ])

  await sayHi('world')
  // -> [ 'Hello, world!', '¡Hola, world!', 'Bonjour, world!' ]

}()

Params:

TypeNameDescription
Function[]funcsArray of functions
*xAny value

Return:

TypeDescription
PromiseFulfills 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:

import { race, delay } from 'powerglove'

void async () => {

  const fast = delay(200)(x => `${x} Speed Racer`)

  const faster = delay(100)(x => `${x} Racer X`)

  const fastest = delay(0)(x => `${x} Chim Chim`)

  const announceWinner = race([
    fast,
    faster,
    fastest
  ])

  await announceWinner('And the winner is...')
  // -> `And the winner is... Chim Chim!`

}()

Params:

TypeNameDescription
Function[]funcsArray of functions
*xAny value

Return:

TypeDescription
PromiseFulfills 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:

import { until } from 'powerglove'

void async () => {

  const minusminus = x => x - 1

  const smallEnough = x => x <= 0

  const subtractAll = until(smallEnough)(minusminus)

  await subtractAll(100000)
  // -> 0

  const plusplus = x => x + 1

  const largeEnough = x => x >= 100000

  const addALot = until(largeEnough)(plusplus)

  await addALot(0)
  // -> 100000

}()

Params:

TypeNameDescription
FunctiondoneAccepts value returned by f. f is called repeatedly until this function returns true
FunctionfFunction to be called repeatedly. Passes its own return value into itself on each iteration
*xAny value

Return:

TypeDescription
PromiseFulfills 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:

import { when } from 'powerglove'

void async () => {

  const over9000 = lvl => lvl > 9000

  const praise = lvl => `Holy crap! ${lvl}?! THAT'S OVER 9000!`

  const insult = lvl => `Pffft. ${lvl}? Is that all you got???`

  const analyzePowerLevel = when(over9000)(praise)(insult)

  await analyzePowerLevel(9001)
  // -> `Holy crap! 9001?! THAT'S OVER 9000!`

  await analyzePowerLevel(1)
  // -> `Pffft. 1? Is that all you got???`

}()

Params:

TypeNameDefaultDescription
FunctiontestAccepts x; returns true or false
FunctionpassCalled with x if test returns true
Functionfaila => aCalled with x if test returns false
*xAny value

Return:

TypeDescription
PromiseFulfills with value returned by pass or fail

delay

Number -> (a -> *) -> a -> Promise -> *

Accepts ms, number of milliseconds to wait, before executing function f.

Example:

import { delay } from 'powerglove'

void async () => {

  const timeSince = delay(300)(ms => Date.now() - ms)

  await timeSince(Date.now())
  // -> ~300ms

}()

Params:

TypeNameDescription
NumberfuncsArray of functions
FunctionfFunction to be called after timeout
*xAny value

Return:

TypeDescription
PromiseFulfills with value returned by f(x)

Keywords

FAQs

Package last updated on 01 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc