Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "xform/toggle"

Index

Functions

Functions

toggle

  • toggle<T>(on: T, off: T, initial?: undefined | false | true): Transducer<any, T>
  • toggle<T>(on: T, off: T, initial: boolean, src: Iterable<any>): IterableIterator<boolean>
  • Stateful transducer which accepts any input and flips between given on / off values for every value received. The initial state can be optionally provided (default: false) and must be given if used as an iterator.

    example
    [...toggle(1, 0, false, [1, 2, 3, 4])]
    // [ 1, 0, 1, 0 ]
    
    [...tx.toggle("on", "off", true, [1, 2, 3, 4])]
    // [ 'off', 'on', 'off', 'on' ]

    Type parameters

    • T

    Parameters

    • on: T

      result for "on" state

    • off: T

      result for "off" state

    • Optional initial: undefined | false | true

      initial state

    Returns Transducer<any, T>

  • Type parameters

    • T

    Parameters

    • on: T
    • off: T
    • initial: boolean
    • src: Iterable<any>

    Returns IterableIterator<boolean>

Generated using TypeDoc