ApplyExtension<T extends Object> extension
Extension for conditionally transforming values.
This extension provides methods to apply transformations based on conditions, returning either the transformed value or the original value unchanged. Unlike TakeExtension, which returns null or the value, this applies transformations that always return a value of the same type.
Common use cases:
- Building configuration objects with conditional properties
- Applying transformations based on runtime conditions
- Fluent builder patterns with conditional steps
- Debugging-enabled features
Example:
final config = Config()
.applyIf(isProduction, (c) => c.copyWith(debug: false))
.applyIfLazy((c) => c.environment == 'test', (c) => c.copyWith(timeout: 5000));
- on
-
- T
Methods
-
applyIf(
bool condition, T block(T value)) → T -
Available on T, provided by the ApplyExtension extension
Conditionally transforms this value and returns the result. -
applyIfLazy(
bool predicate(T value), T block(T value)) → T -
Available on T, provided by the ApplyExtension extension
Conditionally transforms this value based on a lazy predicate.