guild icon
Toit
#Multiple named arguments
Thread channel in help
addshore
addshore 04/16/2025 11:01 AM
I was thinking of doing sometihng like this

constructor action/Lambda --then/Lambda?=null:

But I would want to be able to call it with multiple named arguments
Such as
foo --then=(::print foo) --then=(::print bar)
However this isn't possible in toit, what would the closest thing be?

Or is there an example of fluid / chained function calls
addshore
addshore 04/16/2025 11:02 AM
I was kind of aiming for something like this

awaitAll Promise (:: print "Hello") .then (:: print "Hello again")

And got distracted by trying named arguments while realizing that this stuf of indenting doesnt work for the chaining
addshore
addshore 04/16/2025 11:05 AM
maybe I should be trying chaining with blocks though
addshore
addshore 04/16/2025 01:19 PM
TLDR: I was hoping for something like this, but Ic ant seem to ake it work any way aroud I try :🙂:

Promise (:: print "Hello 1") .then (:: print "Hello 2") .then (:: print "Hello 3") .then (:: print "Hello 4") .await
addshore
addshore 04/16/2025 01:20 PM
I could probably also create a similar pattern with variadics, but no variadics in toit either as far as I can see
floitsch
floitsch 04/17/2025 06:13 AM
chaining doesn't really work well in Toit, and we thus don't use it really in our APIs. (And that comes from the creators of the Dart lib, which "breathes" it...)
There is also no way to have the same named argument multiple times (or variadic functions).

I would probably take a list instead.
Promise [ :: print "Hello 1", :: print "Hello 2", ... ]
👍1
addshore
addshore 04/17/2025 09:40 AM
I was going to give lists a go but figured I'd wait for your thoughts first :🙂:
So I'll try that out today
7 messages in total