Method Syntax
Method-style calls let ordinary functions read like a pipeline.
UFCS
The compiler term is UFCS: x.f(y) means f(x, y). The guide mostly calls this method syntax.
method-style.brp
text: String = to_string(42)
same: String = 42.to_string()Chains
A chain reads left to right and keeps nested calls from growing inward.
chain.brp
label: String = " Alice Smith ".trim().split(" ").join("-")Imported Functions As Methods
Functions whose first parameter matches the receiver can be available as methods, especially on prelude types and imported module types.
imports.brp
import:
list: map
values.map(pure func(x): x + 1)Field Access Precedence
Real fields such as player.score win before method lookup.
fields.brp
record Player { score: Int }
player: Player = { score = 10 }
value: Int = player.scoreExample
pipeline.brp
import:
list: filter, join, map
func main(args: List[String]) -> Void:
values: List[Int] = [3, -1, 4]
chained: String = values
.filter(func(x): x > 0)
.map(func(x): x * 2)
.map(func(x): to_string(x))
.join(", ")
nested: String = join(
map(
map(
filter(
values,
func(x): x > 0,
),
func(x): x * 2,
),
func(x): to_string(x),
),
", ",
)
print(chained)
print(nested)
Try It
terminal
blorp run pipeline.brp