conductor
Why I'm building conductorGitHub
v1.5.0
v1.5.0
  • Introduction
  • Overview
    • Introduction
    • Core concepts
  • API reference
    • always
    • append
    • apply
    • arity
    • branch
    • capitalize
    • compose
    • concat
    • curry
    • curryN
    • delay
    • dump
    • entries
    • equals
    • equalsBy
    • factory
    • filter
    • findIndex
    • flatten
    • flip
    • forEach
    • get
    • head
    • ifElse
    • identity
    • into
    • isPromise
    • iterate
    • join
    • keys
    • map
    • merge
    • mergeBy
    • next
    • not
    • pluck
    • prepend
    • random
    • reduce
    • replace
    • slice
    • some
    • split
    • take
    • then
    • toLowerCase
    • transduce
    • transformers
      • transformers/filter
      • transformers/map
    • type
    • upsert
    • values
  • Guides
    • example use cases
    • checkGuards
Powered by GitBook
On this page
  • description
  • example
  1. API reference

branch

branch :: (Function f, Function g, Function h, ...)
    => (a, b, c, ...)
    => Array [f(a, b, c, ...), g(a, b, c, ...), h(a, b, c, ...), ...]

description

branch takes as many functions as you want as parameters and creates branches (think Git branches) with them. It returns a new function which will forward whatever arguments are passed to the different branches you created, and return an array where each item is the result of a branch function. The branches are run in parallel.

example

import { branch } from 'conductor'

const numbers = [1, 3, 5]
const sum = (...args) => args.reduce((a, b) => a + b)
const multiply = (...args) => args.reduce((a, b) => a * b)
const sumAndMultiply = branch(sum, multiply)

sumAndMultiply(numbers) // [9, 15]
PreviousarityNextcapitalize

Last updated 7 years ago