Early preview: syntax, standard library APIs, and tooling may change.

Safety and Runtime ModelParallel Collection Work

Parallel Collection Work

List.parallel splits pure collection transformations across worker threads.

Pure Callbacks

The callback is pure, which prevents shared mutable state and I/O inside the parallel work.

items.parallel(
    pure func(chunk): chunk.map(pure func(x): x * 2)
)

List.parallel()

parallel hands the callback a ParallelList view with parallel-safe map, filter, and filter_map.

items.parallel(
    pure func(chunk): chunk.map(pure func(x): x * x)
)

When It Helps

Use it for expensive per-element work, not tiny transforms where scheduling costs dominate.

pure func expensive(n: Int) -> Int:
	n * n + n

Collecting Results

parallel returns an ordinary List after the scoped work completes.

results: List[Int] = transform(items)

Example

parallel-chunks.brp
pure func expensive(n: Int) -> Int:
	n * n + n


pure func transform(items: List[Int]) -> List[Int]:
	items.parallel(pure func(chunk: ParallelList[Int]):
		chunk.map(pure func(n): expensive(n))
	)


pure func sum(items: List[Int]) -> Int:
	var total: Int = 0
	for item in items:
		total += item
	total


func main(args: List[String]) -> Void:
	print(sum(transform([1, 2, 3, 4]))) -- prints: 40

Try it

terminal
blorp run parallel-chunks.brp