This isn’t nice in term of reviewing/maintainability, but obviously not blocking. The exact context in which I needed it was in another question I recently asked
let wrapp-section(
...
) = {
let fn = none
let fenced = ()
for it in body.children {
if (is-heading(it) and it.fields().at("depth") < depth) {
if fn != none {
// Complete the last fence
fn(fenced.join())
fn = none
fenced = ()
}
// some code…
} else if is-heading(it) and it.fields().at("depth") == depth {
if fn != none {
// Complete the last fence
fn(fenced.join())
fn = none
fenced = ()
}
// some other code…
} else if fn != none {
// ...
} else {
// ...
}
}
// ...
}
As you can see, the following block is repeated two times, and I wanted to create what would be a macro/lambda in other languages to factorize it:
if fn != none {
// Complete the last fence
fn(fenced.join())
fn = none
fenced = ()
}