Vibescript Showcase
Batch enrichment
Add fields to many records at the same time with Tasks.map.
Source
showcase/concurrency/batch_enrich.vibe
# title: Batch enrichment
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Add fields to many records at the same time with Tasks.map.
# description: Each task gets a copy of one record. Results stay in input order.
# tags: concurrency, tasks, structured-concurrency, enrichment
# vibe: 0.4
def enrich_order(order)
subtotal = order[:price] * order[:quantity]
{
id: order[:id],
subtotal: subtotal,
priority: subtotal > 100
}
end
def run
orders = [
{ id: "o1", price: 25, quantity: 2 },
{ id: "o2", price: 60, quantity: 3 },
{ id: "o3", price: 12, quantity: 1 }
]
{
orders: Tasks.map(orders, max: 4, with: :enrich_order)
}
end
Output
Press Run example to run this code.