import { isIterable } from "@thi.ng/checks/is-iterable" ; import type { Reducer , Transducer } from "./api.js" ; import { iterator1 } from "./iterator.js" ; example param on param off param initial export function toggle < T > ( on , off , initial ? ) ; export function toggle < T > ( on , off , initial , src ) ; export function toggle < T > ( on , off , initial = false , src ? ) { return isIterable ( src ) ? iterator1 ( toggle ( on , off , initial ) , src ) : ( [ init , complete , reduce ] ) => { let state = initial ; return [ init , complete , ( acc ) => reduce ( acc , ( state = ! state ) ? on : off ) , ] ; } ; }