KPaths¶
KPaths provides typed, comparable KeyPaths and CaseKeyPaths for Kotlin values. It is inspired by Swift’s key-path expressions and Point-Free’s CasePaths.
Swift KeyPaths use \Type.property expressions. KPaths uses Kotlin property references and
factories such as keyPath(Person::name) to create the equivalent typed value. CaseKeyPaths extend
the same idea to sealed cases through caseKeyPath; the optional JVM reflection artifact adds
casePathsOf for conventional data-class constructors.
Learn KPaths in order¶
- Read KeyPaths for property references, value-style writes, composition, and nullable paths.
- Read CaseKeyPaths for matching, independent embedding, payload factories, and sealed-case composition.
- Read Generated catalogs to decide when
@Pathableis more discoverable than a direct factory.
Then choose the guide that matches the problem at hand:
- Recipes collects composition, collection, and case-classification patterns.
- API design explains when an API should retain a KeyPath or CaseKeyPath instead of accepting an opaque closure.
- Advanced KeyPaths covers named derived, indexed, keyed, and whole-value paths.
- Identity and type metadata explains structural equality,
PathId, andTypeId.
The API reference is the source of truth for every public declaration and overload. It includes the public core, annotation, and optional JVM-reflection modules, but deliberately excludes processor internals and the sample module.
Platforms¶
kpaths-core and kpaths-annotations publish JVM and iOS Kotlin/Native variants. The normal
property and explicit case-path factories work on both. kpaths-reflection-jvm is deliberately
JVM-only: casePathsOf(...).pathFor(...) needs Kotlin/JVM runtime reflection. On Native, prefer
the explicit factories or generated @Pathable catalogs.
Build locally¶
Install the pinned documentation dependency once, then build the complete static site:
python3 -m venv .venv-docs
. .venv-docs/bin/activate
python3 -m pip install -r docs/requirements.txt
./gradlew docsBuild
The result is build/docs/site. Run ./gradlew docsServe to serve that exact output locally at
http://localhost:8000. The tasks automatically use .venv-docs/bin/python; use
-PdocsPython=/absolute/path/to/python to choose another interpreter in CI.