Skip to content

Instantly share code, notes, and snippets.

@sorgfal
Last active June 8, 2022 14:20
Show Gist options
  • Select an option

  • Save sorgfal/e5c1d3aac87e17e6dbd1e6152a5aade5 to your computer and use it in GitHub Desktop.

Select an option

Save sorgfal/e5c1d3aac87e17e6dbd1e6152a5aade5 to your computer and use it in GitHub Desktop.
apply
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