effect-layers

Explain identity-based memoization for Effect Layer compositions using Layer.fresh and Layer.memoize.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/lucas-barake/dotai --skill effect-layers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-layers
Source: https://github.com/lucas-barake/dotai/tree/main/canonical/skills/effect-layers
Command: npx skills add https://github.com/lucas-barake/dotai --skill effect-layers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Effect Layer memoization can lead to unintended sharing across layer compositions. This guide explains identity-based caching, how to escape it with Layer.fresh, and how to control memoization using Layer.memoize and ManagedRuntime to ensure predictable test and runtime behavior.

Core Features & Use Cases

  • Identity-based memoization ensures a single instance per layer reference within a build.
  • Layer.fresh escapes memoization, enabling multiple independent instances when needed.
  • Layer.memoize enables lazy construction with deterministic caching within a scope.
  • ManagedRuntime allows sharing or isolating memoization across runs for stable tests and production workflows.
  • Patterns for testing describe per-block isolation via it.layer and shared infrastructure via globalSetup.

Quick Start

Apply Layer.merge with your base layers and use Layer.fresh only when you need separate instances to escape memoization.

Frequently Asked Questions about effect-layers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does identity-based memoization work for Effect Layers?

Layer.fresh escapes identity-based memoization in Effect, enabling the creation of multiple independent instances of the same layer when separate states are needed within a single composition.

How do I control memoization scope in Effect tests?

Use Layer.memoize to enable lazy construction with deterministic caching bounded by a specific scope. ManagedRuntime allows sharing or isolating memoization maps across test runs for predictable behavior.

What is the best way to isolate Effect Layers across test blocks?

For per-block isolation in Effect tests, utilize it.layer to scope layer instances individually. Use globalSetup to provide shared infrastructure layers across multiple test blocks when needed.

Why are my Effect Layers sharing state across different test runs?

Effect Layers share state across test runs due to default identity-based memoization caching a single instance per layer reference. ManagedRuntime can isolate memoization maps per run to prevent this.

When should I use Layer.fresh instead of Layer.merge in Effect?

Use Layer.fresh instead of Layer.merge when you need to escape memoization and generate multiple independent layer instances. Apply Layer.merge with base layers when shared memoized instances are desired.