mongez-reinforcements-lazy

Memoize lazy values to break circular imports in TypeScript projects.

3|2|Updated Dec 20, 2021
One-click install
npx skills add https://github.com/hassanzohdy/reinforcements --skill mongez-reinforcements-lazy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mongez-reinforcements-lazy
Source: https://github.com/hassanzohdy/reinforcements/tree/main/skills/lazy
Command: npx skills add https://github.com/hassanzohdy/reinforcements --skill mongez-reinforcements-lazy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Managing module imports in complex TypeScript projects can lead to circular dependencies and eager evaluation of costly computations. This Skill provides memoised lazy values to break circular imports and delay work until needed.

Core Features & Use Cases

  • lazy: create a memoised producer that runs once and caches the value.
  • lazy.async: memoised promises for asynchronous producers.
  • lazy.from: pre-resolved lazy values for testing or symmetry.
  • isLazy: type guard to narrow to Lazy values.
  • Isolates circular-dependency risks and simplifies dependency graphs in large apps.

Quick Start

Resolve a lazy value on first access to avoid unnecessary work.

Frequently Asked Questions about mongez-reinforcements-lazy

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

FAQPage Schema
How do I break circular imports in TypeScript using memoization?

Memoization breaks circular imports in TypeScript by deferring heavy computations until first access. This prevents eager evaluation during module initialization, safely isolating dependency cycles and startup bottlenecks.

What is deferred computation and when do I need lazy values?

Deferred computation delays costly calculations until their results are accessed. You need lazy values when managing complex module dependencies to prevent eager evaluation and avoid slowing down application startup.

How do I memoize asynchronous producers in a JavaScript project?

You memoize asynchronous producers using lazy.async, which creates memoised promises. This ensures the asynchronous operation runs once and caches the resolved value for subsequent accesses across modules.

Can I use lazy values for testing with pre-resolved data in TypeScript?

Yes, you can use lazy.from to provide pre-resolved lazy values for testing. This maintains symmetry with lazy producers while injecting deterministic, ready-to-use data without executing actual computation logic.

How do I check if a variable is a Lazy value using type guards?

You use the isLazy type guard to safely narrow variable types to Lazy values. This verifies whether a value is a memoised lazy producer, ensuring type safety before attempting to resolve it.

What are the limitations of memoized lazy values for dependency management?

Memoized lazy values run producers only once, meaning subsequent calls receive cached results without re-evaluation. This deterministic semantics approach is unsuitable if your computation requires fresh results on every access.