identity<T> function

T identity<T>(
  1. T a
)

Returns the given a.

Same as id.

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', identity);
final withId = result.when((success) => '$success', identity);

Implementation

T identity<T>(T a) => a;