import { Evt } from "../Evt"; import { NonPostable } from "../types/helper/NonPostable"; import { UnpackEvt } from "../types/helper/UnpackEvt"; type Ctx = import("../Ctx").Ctx; export function mergeImpl>>( ctx: Ctx | undefined, evts: readonly EvtUnion[] ): Evt> { const evtUnion = new Evt>(); const callback = (data: UnpackEvt) => evtUnion.post(data) evts .forEach( evt => { if (ctx === undefined) { evt.attach(callback); } else { evt.attach(ctx, callback); } } ) ; return evtUnion; } export function merge>>( ctx: Ctx, evts: readonly EvtUnion[] ): Evt>; export function merge>>( evts: readonly EvtUnion[] ): Evt>; export function merge>>( p1: Ctx | readonly EvtUnion[], p2?: readonly EvtUnion[] ): Evt> { return "length" in p1 ? mergeImpl(undefined, p1) : mergeImpl(p1, p2!) ; }