Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identity function in Dart?

Tags:

dart

Does Dart have an identity function? I understand that I can just write, (x) => x, but it would seem to be slightly easier to understand code if there was something like Function.identity?

like image 306
Mark Avatar asked May 14 '19 05:05

Mark


1 Answers

Not in the core libraries (but possibly in some third-party package). It's trivial to make your own generic function:

T identity<T>(T x) => x;
like image 143
jamesdlin Avatar answered Oct 23 '22 21:10

jamesdlin