Skip to content

Instantly share code, notes, and snippets.

@gosoccerboy5
Last active July 25, 2021 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gosoccerboy5/8559b6c8fe40d0586da497c5ba9bb2f7 to your computer and use it in GitHub Desktop.
Save gosoccerboy5/8559b6c8fe40d0586da497c5ba9bb2f7 to your computer and use it in GitHub Desktop.
Using numbers - as functions
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