Closed Jeffail closed 5 months ago
I would second having support for imperative match
as well as if
statements so that we could have "switch" statements like this:
root = this
match this.status {
"pending" => {
root.status = "confirmed"
root.confirmed_at = now()
},
"canceled" => {
if random_int() % 2 == 0 {
root.canceled_at = now()
} else {
root = deleted()
}
}
}
Although, possible "gotchas" for this match
statement form would be the new this
context in the "case" blocks.
Added in v4.26.0.
Bloblang is pretty cool, and a lot of that coolness is that everything is an expression and mutations are methods you can chain:
Including error handling and flow control. However, we're also imperative as assignments work as a series of isolated mapping statements:
Currently if a map author wants to use a conditional expression to toggle a series of imperative assignments they need to refactor their assignments into a single one:
Ultimately the statements acting as expressions is the more useful paradigm and I believe it was right to emphasise solving problems this way as it's much more powerful. Traditionally, users that want a truly imperative scripting/mapping environment have lots of options within Benthos such as the
javascript
andawk
processors.However, now that the language is maturing and has been stable for a long time we should consider adding if-expressions that act upon root level imperative assignments. There are some things to consider:
if <foo> { <bar> }
being shorthand forroot = if <foo> { <bar> }
.