Created with <3 with dartpad.dev.
Created
June 27, 2023 14:42
-
-
Save knaeckeKami/6f746367a4eff1f1cf22dc7aec98abcd to your computer and use it in GitHub Desktop.
astonishing-spray-1411
This file contains 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
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