Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.mapEffectsconstsrc/Hyperlink.ts:1249
<Impl, const S extends Spec, Out = Impl>(
  impl: Impl,
  spec: S,
  transform: (
    effect: Effect.Effect<unknown, never, never>
  ) => Effect.Effect<unknown, never, never>
): Out

The generic impl-transform primitive — the Hyperlink counterpart to Store.mapEffects. Walk impl per its spec (flattenSpec keys aligned onto the impl via flattenImpl) and pass each Effect method's returned Effect through transform, then re-nest (nestService). A stream: true leaf — a Hyperlink.stream member (a Stream impl) or a ref field (a Subscribable impl) — is left untouched, as is a LocalMethod leaf.

transform is applied uniformly; whether it changes types is expressed through the result:

  • Type-preserving transforms (withSpan / retry) leave the type unchanged — Out defaults to Impl.
  • Type-changing transforms (stripping R, like provideContext) supply an explicit Out computed per method by a mapped type (e.g. ProvidedContext).
reactivityflattenSpecflattenImplEffectnestServiceHyperlink.streamStreamrefSubscribableLocalMethodprovideContextProvidedContext
Source src/Hyperlink.ts:124933 lines
export const mapEffects = <Impl, const S extends Spec, Out = Impl>(
  impl: Impl,
  spec: S,
  transform: (
    effect: Effect.Effect<unknown, never, never>,
  ) => Effect.Effect<unknown, never, never>,
): Out => {
  const flatSpec = flattenSpec(spec);
  // Tree-walk/rebuild idiom (as in `flattenImpl` at every wire call site): the impl is a type-erased
  // record here, walked by the spec's flat paths.
  const flatImpl = flattenImpl(impl as Record<string, unknown>, flatSpec);

  const mapped: Record<string, unknown> = {};
  for (const [path, member] of Object.entries(flatImpl)) {
    const leaf = flatSpec[path];
    // Leave streams (and `ref` → Subscribable, which is `stream: true`) and local members untouched;
    // map only the Effect methods.
    if (
      leaf === undefined ||
      isLocalMethod(leaf) ||
      (Predicate.hasProperty(leaf, "stream") && leaf.stream === true)
    ) {
      mapped[path] = member;
    } else {
      mapped[path] = mapEffectMember(member, transform);
    }
  }

  const built = nestService(mapped);
  // Same structural-rebuild idiom as `Store.mapEffects`: the reassembled object is asserted once here
  // (as `Out` — the caller-supplied per-method result, or `Impl`).
  return built as Out;
};
Referenced by 1 symbols