Dart function invoking

From rodydavis/skills · View interactive version

Dart function invoking is an AI agent skill from the GitHub repository rodydavis/skills. Discover the surprising flexibility of calling Dart functions, including mixed positional and named arguments, the `.call` operator, and dynamic invocation with `Function.apply`.

How to use this skill

Skill file

Various Ways to Invoke Functions in Dart

There are multiple ways to call a Function in Dart.

The examples below will assume the following function:

void myFunction(int a, int b, {int? c, int? d}) {
  print((a, b, c, d));
}

But recently I learned that you can call a functions positional arguments in any order mixed with the named arguments. 🤯

myFunction(1, 2, c: 3, d: 4);
myFunction(1, c: 3, d: 4, 2);
myFunction(c: 3, d: 4, 1, 2);
myFunction(c: 3, 1, 2, d: 4);

In addition you can use the CODE0 operator to invoke the function if you have a reference to it:

myFunction.call(1, 2, c: 3, d: 4);

You can also use CODE0 to dynamically invoke a function with a reference but it should be noted that it will effect js dart complication size and performance:

Function.apply(myFunction, [1, 2], {#c: 3, #d: 4});

All of these methods print the following:

(1, 2, 3, 4)

Demo

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.