MCPcopy Create free account
hub / github.com/Snowflyt/tinyeffect / zip

Method zip

src/effected.ts:1002–1032  ·  view source on GitHub ↗
(that: Effected<Effect, unknown>, mapper?: any)

Source from the content-addressed store, hash-verified

1000 mapper: (a: R, b: S) => T | Generator<G, T, unknown> | Effected<G, T>,
1001 ): Effected<E | F | G, T>;
1002 zip(that: Effected<Effect, unknown>, mapper?: any): Effected<Effect, unknown> {
1003 return effected(() => {
1004 const iterator = this[Symbol.iterator]();
1005 const thatIterator = that[Symbol.iterator]();
1006 let selfDone = false;
1007 let selfDoneValue: unknown;
1008 let thatDone = false;
1009 let appendedIterator: Iterator<Effect, unknown, unknown>;
1010 return {
1011 next: (...args: [] | [unknown]) => {
1012 if (selfDone && thatDone) return appendedIterator.next(...args);
1013 if (!selfDone) {
1014 const result = iterator.next(...args);
1015 if (!result.done) return result;
1016 selfDone = true;
1017 selfDoneValue = result.value;
1018 }
1019 const thatResult = thatIterator.next(...args);
1020 if (!thatResult.done) return thatResult;
1021 thatDone = true;
1022 if (mapper) {
1023 const it = mapper(selfDoneValue, thatResult.value);
1024 if (!(it instanceof Effected) && !isGenerator(it)) return { done: true, value: it };
1025 appendedIterator = it[Symbol.iterator]();
1026 return appendedIterator.next();
1027 }
1028 return { done: true, value: [selfDoneValue, thatResult.value] };
1029 },
1030 };
1031 }) as never;
1032 }
1033
1034 /**
1035 * Catch an error effect with a handler.

Callers

nothing calls this directly

Calls 2

effectedFunction · 0.85
isGeneratorFunction · 0.85

Tested by

no test coverage detected