VarArgsFunction<T> class
A class that enables handling variable numbers of positional and named arguments dynamically. This class intercepts method calls and passes the arguments to a user-defined callback function.
Example usage:
// Example 1: Handle only positional arguments
var superHeroes = VarArgsFunction<void>((args, kwargs) {
for (final superHero in args) {
print("There's no stopping $superHero");
}
});
superHeroes('UberMan', 'Exceptional Woman', 'The Hunk'); // Positional args only
// Example 2: Handle both positional and named arguments
var myFunc = VarArgsFunction<String>((args, kwargs) {
return 'Got args: $args, kwargs: $kwargs';
});
print(myFunc(1, 2, 3, x: 'hello', y: 'world')); // Positional + Named args
print(myFunc(10, 20, x: true, y: false)); // Another set of Positional + Named args
print(myFunc('A', 'B', 'C')); // Positional args only
- Implementers
Constructors
-
VarArgsFunction(VarArgsCallback<
T> callback) - Constructor for creating a VarArgsFunction instance.
Properties
-
callback
→ VarArgsCallback<
T> -
A callback function that handles the positional and named arguments.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
dynamic args, {Map< String, dynamic> kwargs = const <String, dynamic>{}}) → T - Makes the object directly callable like a function.
-
compose<
R> (VarArgsFunction< R> g(T)) → VarArgsFunction<R> - Composes this function with another function, creating a new function that passes the result of this function as input to the other function.
-
curry(
int arity) → Function - Implements currying, converting a function that takes multiple arguments into a sequence of functions that each take a single argument.
-
debounced(
Duration delay) → FutureVarArgsFunction< T> - Creates a debounced version of this function that only executes after a specified delay has passed without any new invocations.
-
map<
R> (R transform(T result)) → VarArgsFunction< R> - Creates a new VarArgsFunction that applies a transformation to the result of this function.
-
memoized(
) → VarArgsFunction< T> - Creates a memoized version of this function that caches results.
-
memoizedWithKey(
String keyGenerator(List, Map< String, dynamic> )) → VarArgsFunction<T> - Creates a memoized version of this function with a custom key generator.
-
noSuchMethod(
Invocation inv) → T -
This method is overridden to capture any dynamic method calls made on
the instance. It processes both positional and named arguments.
override
-
partial(
[List preArgs = const [], Map< String, dynamic> preKwargs = const <String, dynamic>{}]) → VarArgsFunction<T> - Creates a new VarArgsFunction with pre-filled arguments.
-
throttled(
Duration interval) → FutureVarArgsFunction< T> - Creates a throttled version of this function that executes at most once per specified duration, regardless of how many times it's called.
-
toFunction<
R> (R fn()) → R Function() - Converts this VarArgsFunction to a standard Dart function with the specified signature. This is useful when you need to pass the function to APIs that expect specific function signatures.
-
toString(
) → String -
A string representation of this object.
inherited
-
withRetry(
int maxRetries, [Duration? delay]) → FutureVarArgsFunction< T> - Creates a version of this function that will retry execution a specified number of times if it throws an exception.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromFunction<
R> (Function function) → VarArgsFunction< R> - Factory constructor to create a VarArgsFunction from a standard Dart function.