{"version":3,"file":"concat.cjs","sources":["../../../src/operators/concat.ts"],"sourcesContent":["import { BinaryOperator, DifferenceStreamWriter } from '../graph.js'\nimport { StreamBuilder } from '../d2.js'\nimport type { IStreamBuilder, PipedOperator } from '../types.js'\n\n/**\n * Operator that concatenates two input streams\n */\nexport class ConcatOperator<T, T2> extends BinaryOperator<T | T2> {\n  run(): void {\n    for (const message of this.inputAMessages()) {\n      this.output.sendData(message)\n    }\n\n    for (const message of this.inputBMessages()) {\n      this.output.sendData(message)\n    }\n  }\n}\n\n/**\n * Concatenates two input streams\n * @param other - The other stream to concatenate\n */\nexport function concat<T, T2>(\n  other: IStreamBuilder<T2>,\n): PipedOperator<T, T | T2> {\n  return (stream: IStreamBuilder<T | T2>): IStreamBuilder<T | T2> => {\n    if (stream.graph !== other.graph) {\n      throw new Error(`Cannot concat streams from different graphs`)\n    }\n    const output = new StreamBuilder<T | T2>(\n      stream.graph,\n      new DifferenceStreamWriter<T | T2>(),\n    )\n    const operator = new ConcatOperator<T, T2>(\n      stream.graph.getNextOperatorId(),\n      stream.connectReader(),\n      other.connectReader(),\n      output.writer,\n    )\n    stream.graph.addOperator(operator)\n    return output\n  }\n}\n"],"names":["BinaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;AAOO,MAAM,uBAA8BA,MAAAA,eAAuB;AAAA,EAChE,MAAY;AACV,eAAW,WAAW,KAAK,kBAAkB;AAC3C,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAEA,eAAW,WAAW,KAAK,kBAAkB;AAC3C,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AAMO,SAAS,OACd,OAC0B;AAC1B,SAAO,CAAC,WAA2D;AACjE,QAAI,OAAO,UAAU,MAAM,OAAO;AAChC,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA+B;AAErC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,MAAM,cAAA;AAAA,MACN,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO;AAAA,EACT;AACF;;;"}