You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
I know that there is a Function.apply method that works just like the main function.
I have an idea to make a new function let's say Function.prepare that prepare the function to be called then calls the function later.
Example:
voidexample(String str) {
print(str)
}
voidmain() {
var preparedFunction =Function.prepare(example, ['hello world']);
// ... do some code then
preparedFunction.call(); // or preparedFunction.apply();
}
The text was updated successfully, but these errors were encountered:
@julemand101 - It's a little different in that Function.apply unwraps a List into the individual arguments. It works to specialize to the argument shape in this example - and that's what I'd do in most cases.
@seifalmotaz - If you do need to handle functions with unknown arity or argument type (I'd avoid this if you can) you can wrap Function.apply. This is not functionality we'll include directly in the SDK.
Object?Function() applyArguments(Function f, List<Object?> args) =>
() =>Function.apply(f, args);
voidexample(String str) {
print(str);
}
voidmain() {
var preparedFunction =applyArguments(example, ['hello world']);
// ... do some code thenpreparedFunction();
}
For more discussion around feature requests fo language level support for partial application, see dart-lang/language#351
Hi.
I know that there is a
Function.apply
method that works just like the main function.I have an idea to make a new function let's say
Function.prepare
that prepare the function to be called then calls the function later.Example:
The text was updated successfully, but these errors were encountered: