Chimney offers three distinct ways to handle transformations, which differ from the standard 'automatic vs semiautomatic' dichotomy found in libraries like Circe. Choosing the right mode affects compilation speed, runtime performance, and how much control you have over where transformations are generated.
1. DSL Mode (Default/Mixed)
By using import io.scalaland.chimney.dsl._, you get a convenient mix of modes. It allows for recursive case class mapping and easy customization via implicits. It is designed to minimize macro expansions by handling recursion internally within a single macro expansion unless you explicitly provide an override implicit.
2. Semiautomatic Derivation
This mode requires you to explicitly call a derivation method. This is useful for caching transformations in companion objects or ensuring a specific instance is used everywhere. It reduces compile time and provides certainty.
Available methods:
Transformer.derive[From, To]PartialTransformer.derive[From, To]Patcher.derive[A, Patch]Transformer.define[From, To].buildTransformer (for customization)PartialTransformer.define[From, To].buildTransformer (for customization)Patcher.define[A, Patch].buildPatcher (for customization)
3. Inlined Derivation
By using import io.scalaland.chimney.inlined._, you use extension methods that generate an inlined expression at the call site without instantiating a type class. This is highly optimized for one-time usage as it avoids type class allocation and defers partial.Result wrapping.
Available methods:
from.into[To].transformfrom.intoPartial[To].transformfrom.using[To].patch