Skip to content

Instantly share code, notes, and snippets.

Last active June 21, 2022 10:45
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Basic examples: Dart call() and Function.apply()
class Adder implements Function {
call(int a, int b) => a + b;
class Incrementer implements Function {
int _amt;
call(int a) => a + _amt;
Function f = (int n, int m, {operation: "add"}) {
if (operation == "add") {
return n + m;
} else {
return n - m;
main() {
Adder myAdder = new Adder();
Incrementer myIncrementer = new Incrementer(2);
print(myAdder(10, 3));
int a = Function.apply(f, [10,3]);
int b = Function.apply(f, [10,3], {new Symbol("operation"): "subtract"});
Copy link

Too bad, there is no way of doing the "apply" thingy with a class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment