Skip to content

Instantly share code, notes, and snippets.

@RockinPaul
Forked from ilikerobots/main.dart
Created June 21, 2022 10:45
Show Gist options
  • Save RockinPaul/7c646302d5e05239e5c8b7ba48a8f1ea to your computer and use it in GitHub Desktop.
Save RockinPaul/7c646302d5e05239e5c8b7ba48a8f1ea to your computer and use it in GitHub Desktop.
Basic examples: Dart call() and Function.apply()
class Adder implements Function {
call(int a, int b) => a + b;
}
class Incrementer implements Function {
int _amt;
Incrementer(this._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));
print(myIncrementer(40));
int a = Function.apply(f, [10,3]);
print(a);
int b = Function.apply(f, [10,3], {new Symbol("operation"): "subtract"});
print(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment