kotlin-context-parameters

Migrate Kotlin code from context receivers to explicit context parameters.

61|3|Updated Mar 1, 2024
One-click install
npx skills add https://github.com/alexandru/social-publish --skill kotlin-context-parameters
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-context-parameters
Source: https://github.com/alexandru/social-publish/tree/main/.agents/skills/kotlin-context-parameters
Command: npx skills add https://github.com/alexandru/social-publish --skill kotlin-context-parameters

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Context parameters let you provide dependencies to functions at the call site by type, reducing boilerplate and improving testability in Kotlin code that previously relied on implicit receivers.

Core Features & Use Cases

  • Scoped dependencies via named context parameters to share services across a call tree.
  • DSL scopes and typeclass-like evidence using context(Type) parameterization for flexible APIs.
  • Migration guidance from context receivers to explicit contextual functions.

Quick Start

Declare a function with a context parameter and call it inside a block that provides a concrete value for that context.

Frequently Asked Questions about kotlin-context-parameters

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

FAQPage Schema
How do I use Kotlin context parameters for dependency injection?

Kotlin context parameters provide dependencies at call sites by type, reducing boilerplate. You declare a function with a context parameter and call it inside a block supplying a concrete value for scoped dependency injection.

How do I migrate from context receivers to context parameters in Kotlin?

Migrating from context receivers to context parameters involves transitioning to explicit contextual functions. This provides guidelines for explicit context wiring, replacing implicit receivers with named parameters for cleaner dependency management.

What are Kotlin context parameters and when should I use them?

Kotlin context parameters let you supply dependencies cleanly at call sites by type. Use them to share services across a call tree, design DSLs with scoped dependencies, or implement typeclass-like evidence for flexible APIs.

Do I need specific compiler flags to enable Kotlin context parameters?

Yes, enabling Kotlin context parameters requires Kotlin language support and specific compiler flags. You must configure these flags to utilize context parameter syntax for explicit contextual dependency wiring.

Can I build DSL scopes using Kotlin context parameters?

Yes, you can build DSL scopes using Kotlin context parameters. By applying context(Type) parameterization, you create flexible APIs with scoped dependencies that share services cleanly across specific call trees.

Why does my Kotlin context parameter migration require explicit wiring?

Migration to Kotlin context parameters requires explicit wiring to replace implicit receivers with explicit contextual functions. This ensures modular code and testability by making dependency provision visible at call sites.