import type {Bud} from '@roots/bud-framework' export interface Callback { (value?: Bud): Promise } export interface Callback { (value?: Bud): unknown } export interface sequence { (fns: Array): Promise } /** * Run a value through an array of asyncronous, non-mutational functions. * * @remarks * Unlike {@link Bud.pipe} the value returned from each function is ignored. */ export const sequence = async function ( fns: Array, ): Promise { const app = this as Bud await fns.reduce(async (promised, fn) => { await promised await fn(app) }, Promise.resolve()) return app } interface SyncCallback { (value: unknown): unknown } export interface sequenceSync { (fns: Array): Bud } /** * Run a value through an array of syncronous, non-mutational functions. * * @remarks * Unlike {@link pipe} the value returned from each function is ignored. */ export const sequenceSync: sequenceSync = ( fns: Array, ): Bud => { fns.map(fn => fn.call(this, this)) return this as unknown as Bud }