kotlin-functions

Guides placement of Kotlin functions across members, extensions, top-level functions, and services.

Updated May 21, 2025
One-click install
npx skills add https://github.com/albertmartorell1975/MeteoMartoCompose --skill kotlin-functions-albertmartorell1975
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-functions
Source: https://github.com/albertmartorell1975/MeteoMartoCompose/tree/main/.agents/skills/kotlin-functions
Command: npx skills add https://github.com/albertmartorell1975/MeteoMartoCompose --skill kotlin-functions-albertmartorell1975

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin codebases often accumulate misleading extension functions on String, primitives, collections, Flow, or third-party types, creating false ownership, domain pollution, and import collisions. This Skill provides a decision procedure for choosing the correct function form so behavior lives on its accurate semantic owner. ## Core Features & Use Cases - Ownership-first decision procedure: A five-step workflow that names the semantic owner, rejects misleading receivers, selects the function form, migrates callers, and verifies compatibility. - Extension gating rules: Strict criteria for when extensions on String, primitives, collections, Flow, framework, or third-party receivers are acceptable. - Form selection table: Maps meaning to member functions, top-level functions, factory/parse methods, injected services, or extensions. - Use Case: When reviewing a PR that adds Long.toDisplayDate(), apply the gates to reject the extension and move time-zone/locale policy into a dedicated formatter collaborator. ## Quick Start Ask the assistant to review a Kotlin function or proposed extension and decide whether it should be a member, top-level function, factory, service, or extension.

Frequently Asked Questions about kotlin-functions

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

FAQPage Schema
When should I use a Kotlin extension function?▼

Use an extension only when the operation is type-native, valid for every receiver value, free of policy, state, I/O, and dependencies, and materially clearer with receiver syntax. For String, primitives, collections, Flow, or third-party types, all gating conditions must pass.

How do I decide between a member function and a top-level function in Kotlin?▼

Choose a member when the behavior is intrinsic to a project-owned type. Choose a top-level function for cross-type, stateless operations that no single type owns, such as conversions or algorithms spanning multiple types.

Should parsing logic be an extension like String.toUserId?▼

No, parsing belongs to the target type, not String. Use a factory such as UserId.parse(raw) on the companion object or a named top-level parser so the value class owns its own construction.

When should Kotlin behavior go into an injected service instead of a function?▼

Use an injected service or collaborator when behavior retains policy, state, I/O, clock, locale, or dependencies. If none of these apply, prefer a stateless function with explicit parameters instead.

Why are extensions on library or framework types discouraged?▼

They create false ownership, pollute the domain, add noisy completions and imports, and risk collisions with future library members. Private or internal scope only helps when every other ownership gate also passes.