AlsoExtension<T extends Object> extension
Extension for executing side effects while returning the original value.
This extension provides a convenient way to perform operations (like logging or validation) without transforming the value. The block executes as a side effect, and the original value is always returned.
Common use cases:
- Logging intermediate values in a chain
- Validation checks
- Debugging value transformations
- Side effects in fluent APIs
Example:
final user = fetchUser()
.also((u) => print('Fetched: ${u.name}'))
.also((u) => analytics.track('user_loaded'));
- on
-
- T
Methods
-
also(
void block(T value)) → T -
Available on T, provided by the AlsoExtension extension
Executes a side effect block and returns this value unchanged.