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
  • examples
  • basic example
  1. API reference

forEach

forEach :: (Function callback, Collection collection) => undefined | Promise<undefined>

description

Iterates over a collection and calls the provided callback function for each item in the collection. The callback function should have the following signature:

(Any value, Any key, Collection collection) => Any

where:

  • value is the current item's value

  • key is the item's key or index (depending on if the collection is an Array, a Set, an Object, or a Map).

  • collection is the collection being iterated on.

If the collection is a Set, the value and the key will be equal.

If the callback function is asynchronous, forEach will return a Promise which will be resolved when all the promises generated by calling the callback function with each item in the collection are resolved. You could say that forEach is roughly equivalent map, except it returns undefined in the end (ie forEach( asyncFn, collection) ~ Promise.all(collection.map(asyncFn)).then(() => undefined)).

examples

basic example

import { forEach } from 'conductor'

const numbers = [3, 1, 4]
const log = x => console.log(x)
forEach(numbers, log)
// 3
// 1
// 4
PreviousflipNextget

Last updated 7 years ago