Skip to content

Instantly share code, notes, and snippets.

@jakemac53
Created March 21, 2023 14:35
Show Gist options
  • Save jakemac53/0e38e30159163ec7f9b53daadd6270a3 to your computer and use it in GitHub Desktop.
Save jakemac53/0e38e30159163ec7f9b53daadd6270a3 to your computer and use it in GitHub Desktop.
cylindrical-lantern-6201

cylindrical-lantern-6201

Created with <3 with dartpad.dev.

void main() {
print(add << null << 1);
print(add << 1 << null);
print(add << 1 << 2);
}
int add(int a, int b) => a + b;
extension IfNotNull<R, T extends Object> on R Function(T)? {
R? operator <<(T? input) {
var self = this;
if (self == null || input == null) return null;
return self(input);
}
}
extension IfNotNull2<R, S extends Object, T extends Object> on R Function(S, T)? {
R? Function(T)? operator <<(S? input) {
var self = this;
if (self == null || input == null) return null;
return (T next) => self(input, next);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment