import type { Curried } from '../../compositions/curry.js'; import { type Purried, purry } from '../../compositions/purry.js'; import { _isIterable } from '../../controls/_guards.js'; import type { Series, SyncSeries } from '../../controls/types.js'; function* _syncConcat(preceding: SyncSeries, following: SyncSeries): Generator { for (const value of preceding) { yield value; } for (const value of following) { yield value; } } async function* _asyncConcat(preceding: Series, following: Series): AsyncGenerator { const awaitedPreceding = await preceding; if (_isIterable(awaitedPreceding)) { for (const value of awaitedPreceding) { yield value; } } else { for await (const value of awaitedPreceding) { yield value; } } const awaitedFollowing = await following; if (_isIterable(awaitedFollowing)) { for (const value of awaitedFollowing) { yield value; } } else { for await (const value of awaitedFollowing) { yield value; } } } export function concatSync( ...args: Parameters> ): ReturnType>; export function concatSync( ...args: Parameters>> ): ReturnType>>; export function concatSync( ...args: Parameters>> ): ReturnType>> { return purry(_syncConcat)(...args); } export function concatAsync( ...args: Parameters> ): ReturnType>; export function concatAsync( ...args: Parameters>> ): ReturnType>>; export function concatAsync( ...args: Parameters>> ): ReturnType>> { return purry(_asyncConcat)(...args); } /** * Concatenates two series into one series. * * You can invert the order for curried call by `following => concat.sync(preceding, following)` */ export namespace concat { export const sync = concatSync; export const async = concatAsync; }