Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

funcom

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

funcom

Functional composition helpers

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
increased by193.34%
Maintainers
3
Weekly downloads
 
Created
Source

funcom npm

Functional composition helpers.

Install

yarn add funcom

API

compose

Sequential composition of functions invoked in reverse order. Passes return value of the previous function as an argument to the next one.

import { compose } from 'funcom'

const add4 = (a: number) => a + 4
const mult2 = (a: number) => a * 2

const composed = compose(mult2, add4)

console.log(
  composed(2)
)
// (2 + 4) * 2 => 12

composeAsync

import { composeAsync } from 'funcom'

const add4Async= (arg: number) => Promise.resolve(arg + 40)
const mult2 = (a: number) => a * 2

const composed = composeAsync(mult2, add4Async)

console.log(
  await composed(2)
)
// (2 + 4) * 2 => 12

pipe

Sequential composition of functions invoked in direct order. Passes return value of the previous function as an argument to the next one.

import { pipe } from 'funcom'

const add4 = (a: number) => a + 4
const mult2 = (a: number) => a * 2

const piped = pipe(mult2, add4)

console.log(
  piped(2)
)
// (2 * 2) + 4 => 8

pipeAsync

import { pipeAsync } from 'funcom'

const mult2Async = (a: number) => Promise.resolve(a * 2)
const add4 = (a: number) => a + 4

const piped = pipeAsync(mult2Async, add4)

console.log(
  await piped(2)
)
// (2 * 2) + 4 => 8

all

Composition of multiple functions invoked with same initial value. Returns an array of results.

import { all } from 'funcom'

const mult2 = (a: number) => a * 2
const add4 = (a: number) => a + 4
const toString = (a: number) => `${a}`

const piped = all(mult2, add4, toString)

console.log(
  piped(2)
)
// [8, 6, '2']

allAsync

import { allAsync } from 'funcom'

const mult2 = (a: number) => a * 2
const add4 = (a: number) => a + 4
const toStringAsync = (a: number) => Promise.resolve(`${a}`)

const piped = allAsync(mult2Async, add4, toStringAsync)

console.log(
  await piped(2)
)
// [8, 6, '2']

Keywords

FAQs

Package last updated on 14 Aug 2020

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