id<T> function
T
id<T>(
- T a
Returns the given a
.
Same as identity
.
Shortcut function to return the input parameter:
final result = Result<int, String>.success(10);
/// Without using `identity`, you must write a function to return
/// the input parameter `(error) => error`.
final noId = result.when((success) => '$success', (error) => error);
/// Using `identity`/`id`, the function just returns its input parameter.
final withIdentity = result.when((success) => '$success', id);
final withId = result.when((success) => '$success', id);
Implementation
T id<T>(T a) => a;