On this page
article
Transform
transform maps the result of a wrapped function from one type to another.
Transform
What it is
transform maps the result of a wrapped function from one type to another.
When to use it
- Adapting between different data representations.
- Normalising input before processing.
- Converting internal models to DTOs and back.
API reference
| |
Parameters
| Parameter | Type | Description |
|---|---|---|
mapper | R2 Function(R1) | Maps the wrapped function’s result to a new type. |
Examples
Basic example
| |
Real-world example
| |
Best practices
- Keep mappers pure and synchronous.
- Handle nulls and edge cases inside mappers to avoid surprising the target.
Common pitfalls
- Type mismatch: Mappers must match the generic types exactly; otherwise the code will not compile.
- Mapper exceptions: Exceptions thrown in mappers propagate to the caller.