https://toitlang.org/ logo
Multiple named arguments
# help
a
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
I was kind of aiming for something like this
Copy code
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
maybe I should be trying chaining with blocks though
TLDR: I was hoping for something like this, but Ic ant seem to ake it work any way aroud I try 🙂
Copy code
Promise (:: print "Hello 1")
    .then (:: print "Hello 2")
    .then (:: print "Hello 3")
    .then (:: print "Hello 4")
    .await
I could probably also create a similar pattern with variadics, but no variadics in toit either as far as I can see
f
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.
Copy code
Promise [
  :: print "Hello 1",
  :: print "Hello 2",
  ...
]
a
I was going to give lists a go but figured I'd wait for your thoughts first 🙂 So I'll try that out today