Last active
July 25, 2021 22:06
-
-
Save gosoccerboy5/8559b6c8fe40d0586da497c5ba9bb2f7 to your computer and use it in GitHub Desktop.
Using numbers - as functions
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
const pi = 3.1415; | |
extension NumbersAsFunctions on num { | |
num call(num other) => this * other; | |
} | |
void main() { | |
print(2(pi)); // 6.283 | |
} | |
/* | |
Description { | |
Use numbers as functions (you still need the parentheses). | |
} | |
View at { | |
https://dartpad.dev/?null_safety=true&id=8559b6c8fe40d0586da497c5ba9bb2f7 | |
} | |
Inspiration from { | |
https://twitter.com/Sheep_tester/status/1327393867813904384 | |
} | |
Learned technique from { | |
https://dart.dev/guides/language/language-tour#callable-classes | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment