// Copyright (C) 2025 Keygraph, Inc. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License version 3 // as published by the Free Software Foundation. /** * Functional Programming Utilities * * Generic functional composition patterns for async operations. */ // biome-ignore lint/suspicious/noExplicitAny: pipeline functions need flexible typing for composition type PipelineFunction = (x: any) => any | Promise; /** * Async pipeline that passes result through a series of functions. * Clearer than reduce-based pipe and easier to debug. */ export async function asyncPipe(initial: unknown, ...fns: PipelineFunction[]): Promise { let result = initial; for (const fn of fns) { result = await fn(result); } return result as TResult; }