Last active
June 8, 2022 14:20
-
-
Save sorgfal/e5c1d3aac87e17e6dbd1e6152a5aade5 to your computer and use it in GitHub Desktop.
apply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main() { | |
| int? r; | |
| var result = r?.apply<int,int>((a)=>a+1); | |
| var result2 = r!= null? add2(r):null; | |
| } | |
| add2(int a) => a+2; | |
| typedef R ApplyFunction<T,R>(T ); | |
| extension on Object { | |
| R apply<T,R>( ApplyFunction<T,R> fn){ | |
| return fn(this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment