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

Method tap

src/effected.ts:969–985  ·  view source on GitHub ↗

* Tap the return value of the effected program. * @param handler The function to tap the return value. * @returns * * @since 0.2.1

(
    handler: (value: R) => void | Generator<F, void, unknown> | Effected<F, void>,
  )

Source from the content-addressed store, hash-verified

967 * @since 0.2.1
968 */
969 tap<F extends Effect = never>(
970 handler: (value: R) => void | Generator<F, void, unknown> | Effected<F, void>,
971 ): Effected<E | F, R> {
972 return this.andThen((value) => {
973 const it = handler(value);
974 if (!(it instanceof Effected) && !isGenerator(it)) return value;
975 const iterator = it[Symbol.iterator]();
976 return {
977 _effectedIterator: true,
978 next: (...args: [] | [unknown]) => {
979 const result = iterator.next(...args);
980 if (result.done) return { done: true, value };
981 return result;
982 },
983 };
984 }) as never;
985 }
986
987 /**
988 * Combines the return value of the current effected program with another effected program.

Callers

nothing calls this directly

Calls 2

andThenMethod · 0.95
isGeneratorFunction · 0.85

Tested by

no test coverage detected