← All examples
23

Canonical Grid model

Collection Pipelines

Print-shop fulfillment desk built on native collections: List intake, Map catalog, Set stock policy, a Deque job queue, and a folded delivery log.

Scale
Medium
Source
23-collection-pipelines.grid
Length
73 lines
Collection
Start here
Level
Beginner
Runtime
Portable
Version
1.0.0

Watch it in Grid

See this model in motion.

Watch the model respond in the product, then inspect the exact source and checkpoints on this page.

Companion film

The right collection for the job

Change one corrected List quantity and watch the published array and restock pipeline update while the original List and folded ink total stay intact.

49 secGrid 0.63.2
Open film page

What this model gives you

A fulfillment desk using immutable List, Map, Set, and Deque revisions plus a terminal cost pipeline.

20 min to study · Source reviewed 2026-08-25

Continue with guided practice

What to notice

  • Persistent collection updates
  • Map and Set policy
  • Deque queue operations
  • Functional pipelines and REDUCE

Requirements

  • Portable
  • No connector
  • No network

Expected checkpoint

A known state for this walkthrough.

After loading the canonical intake, catalog, queue, and delivery log.

Intake lengths
5 original / 6 revisedA5 / A6
Toner price
92B4
Queue
dispatch j-0987; cancel j-1044; 3 remainD7 / D10 / D12
Restock cost
93.75F2
Ink received
55F6
01 · Revise

Updates return new collections

The original intake, catalog, set, and queue remain available after every change.

02 · Queue

Deque operations make both ends explicit

Rush work enters the front, new work enters the back, and pop results retain both removed and remaining values.

03 · Fold

Pipelines summarize without publishing every step

A terminal filter-map-sum prices shortages while REDUCE accumulates repeated delivery keys.

23-collection-pipelines.grid
Get Grid
MODEL "Collection Pipelines"
DESCRIPTION "Print-shop fulfillment desk built on native collections: List intake, Map catalog, Set stock policy, a Deque job queue, and a folded delivery log."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "collections", "list", "map", "set", "deque", "pipeline"

# Order intake: an indexed List of line quantities. Updates return revisions;
# A1 keeps its original five entries after the correction and the late append.
A1 IS List = VECTOR(4, 12, 7, 25, 3)
A2 = VECTOR_GET(A1, 4)
A3 IS List = VECTOR_SET(A1, 1, 6)
A4 IS List = VECTOR_PUSH(A3, 9)
A5 = VECTOR_LENGTH(A1)
A6 = VECTOR_LENGTH(A4)

# Price catalog: a Map keyed by SKU. MAP_PUT inserts or replaces per key.
B1 IS Map = MAP_OF("ink", 14.5, "paper", 6.25, "toner", 89)
B2 IS Map = MAP_PUT(B1, "staples", 3.1)
B3 IS Map = MAP_PUT(B2, "toner", 92)
B4 = MAP_GET(B3, "toner")
B5 = MATCH(MAP_GET_OPTION(B3, "ribbon"), SOME(price) -> price, NONE() -> 0)
B6 = MAP_LENGTH(B3)
B7 = MAP_CONTAINS(B1, "staples")

# Stock policy: Set membership and set algebra over SKUs. Duplicates collapse.
C1 IS Set = SET_OF("ink", "paper", "toner", "staples", "ink")
C2 IS Set = SET_OF("toner", "ribbon", "drum")
C3 IS Set = SET_INTERSECT(C1, C2)
C4 IS Set = SET_DIFFERENCE(C1, C2)
C5 IS Set = SET_ADD(SET_UNION(C1, C2), "fuser")
C6 = SET_CONTAINS(C4, "paper")
C7 = "ribbon" IN C1
C8 = SET_LENGTH(C5)
C9 = SET_OF("ink", "toner") SUBSET OF C1

# Job queue: a Deque. Rush work enters at the front, arrivals at the back,
# dispatch pops the front, and a cancellation pops the back.
D1 IS Deque = DEQUE("j-1041", "j-1042", "j-1043")
D2 IS Deque = DEQUE_PUSH_BACK(D1, "j-1044")
D3 IS Deque = DEQUE_PUSH_FRONT(D2, "j-0987")
D4 = DEQUE_FRONT(D3)
D5 = DEQUE_BACK(D3)

# A pop returns [removed, remaining]; D3 itself is untouched.
D6 = DEQUE_POP_FRONT(D3)
D7 = INDEX(D6, 1)
D8 IS Deque = INDEX(D6, 2)
D9 = DEQUE_POP_BACK(D8)
D10 = INDEX(D9, 1)
D11 IS Deque = INDEX(D9, 2)
D12 = DEQUE_LENGTH(D11)
D13 = DEQUE_IS_EMPTY(D11)
D14 = DEQUE_TO_ARRAY(D11)

# Restock pipeline: publish the intake List, then filter, map, and total the
# shortfall cost for lines under the reorder point of 10 units.
F1 = VECTOR_TO_ARRAY(A4)
F2 = F1 |> FILTER(quantity => quantity < 10) |> MAP(quantity => (10 - quantity) * 6.25) |> SUM()

# Update pattern: fold the delivery log into a stock-count Map, accumulating
# repeated SKUs. MAP_KEYS reads back in canonical key order.
F4 IS List = VECTOR(TUPLE("ink", 40), TUPLE("paper", 12), TUPLE("drum", 5), TUPLE("ink", 15))
F5 IS Map = REDUCE(MAP_OF(), VECTOR(1, 2, 3, 4)) WITH stock, delivery_index DO
  delivery = VECTOR_GET(F4, delivery_index)
  sku = TUPLE_GET(delivery, 1)
  received = TUPLE_GET(delivery, 2)
  current = MAP_GET(stock, sku) DEFAULT 0
  MAP_PUT(stock, sku, current + received)
END
F6 = MAP_GET(F5, "ink")
F7 = VECTOR_GET(MAP_KEYS(F5), 1) & ", " & VECTOR_GET(MAP_KEYS(F5), 2) & ", " & VECTOR_GET(MAP_KEYS(F5), 3)

END MODEL