Skip to content

Instantly share code, notes, and snippets.

@knaeckeKami
Created June 27, 2023 14:42
Show Gist options
  • Save knaeckeKami/6f746367a4eff1f1cf22dc7aec98abcd to your computer and use it in GitHub Desktop.
Save knaeckeKami/6f746367a4eff1f1cf22dc7aec98abcd to your computer and use it in GitHub Desktop.
astonishing-spray-1411

astonishing-spray-1411

Created with <3 with dartpad.dev.

extension Let<T extends Object> on T? {
S? let<S>(S Function(T) f) {
final self = this;
if(self == null){
return null;
}
return f(self);
}
}
extension ObjectExtension<T> on T {
E let2<E>(E Function(T data) action) => action(this);
}
void main() {
String? s = getNullableString();
s.let(printString);
s.let2(printString);
}
String? getNullableString() => "hi";
void printString(String s) {
print(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment