Pipes and Cascades
Pipes
You can chain kw messages with pipes1 from: 2 to: 3
is single message with two arguments1 from: 2 |> to: 3
is 2 messages with one argument each
Cascades
https://en.wikipedia.org/wiki/Method_cascading
x = a b; c; d
has same effect as
a b
a c
a d
x = a
So its applying all the messages to the receiver, and then returns it.
With the help of cascade you can turn any API into a builder pattern, even if this was not intended!
btn = (Button new);
label: "Hello Adw";
hexpand: true;
vexpand: true;
onClicked: [
"clicked $n times!" echo
n <- n inc
]
// same as
btn = Button new
btn label: "Hello Adw"
btn hexpand: true
btn vexpand: true
btn onClicked: [
"clicked $n times!" echo
n <- n inc
]
Combine |> with ; together
Sometimes it can be useful, but pls don't do it.
String boil -> Nothing!Error =
Error throwWithMessage: "missing $this var"
String validate -> Unit!Error = [
URL = "URL"
SHA = "SHA"
VERSION = "VERSION"
this
contains: URL |> ifTrue: [URL boil];
contains: SHA |> ifTrue: [SHA boil];
contains: VERSION |> ifTrue: [VERSION boil]
]
recipe_template = "SHA:234234234"
recipe_template validate
Last modified: 20 October 2024