also<T> function
T
also<T>(
- T value,
- void fn(
- T
Also/let style (pipe value through function). Roadmap #202.
Runs fn for its side effects on value and returns value unchanged.
Mirrors Kotlin's also for inline configuration within an expression.
Example:
final list = also(<int>[], (l) => l.add(1)); // [1]
Implementation
/// Runs [fn] for its side effects on [value] and returns [value] unchanged.
///
/// Mirrors Kotlin's `also` for inline configuration within an expression.
///
/// Example:
/// ```dart
/// final list = also(<int>[], (l) => l.add(1)); // [1]
/// ```
T also<T>(T value, void Function(T) fn) {
fn(value);
return value;
}