← All examples
27

Canonical Grid model

Named Function Toolkit

In-model named functions: inferred signatures, polymorphic reuse, open records, and lambda composition.

Scale
Small
Source
27-named-functions.grid
Length
52 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

Name the logic. Close the state.

Change one order total and watch a named pricing function and a closed Order choice update the decision while the ledger stays intact.

49 secGrid 0.63.2
Open film page

What this model gives you

A reusable in-model function toolkit over scalars, open records, and collection-shaped inputs.

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

Continue with guided practice

What to notice

  • Named definitions
  • Inferred polymorphic signatures
  • Open record arguments
  • Composition with MAP and REDUCE

Requirements

  • Portable
  • No connector
  • No network

Expected checkpoint

A known state for this walkthrough.

After loading the canonical fee rate and three-job ledger.

Net fee amount
4,576C1
Rush premium
740C2
Billed total
15,700D3
Month result
15,856 / healthy-monthL1 / L2
01 · Define

Repeated business rules get stable names

Fee, premium, floor, shape, and total logic are authored once and reused.

02 · Infer

Calls specialize without boilerplate

Identity works for numbers and text, while open records accept useful extra fields.

03 · Compose

Named functions remain ordinary pipeline parts

MAP and REDUCE reuse the same definitions over the complete job ledger.

27-named-functions.grid
Get Grid
MODEL "Named Function Toolkit"
DESCRIPTION "In-model named functions: inferred signatures, polymorphic reuse, open records, and lambda composition."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "functions", "inference", "composition"

# Named definitions: Grid infers one generalized type scheme per name
identity(value) = value
net_of_fee(amount, fee_rate) = amount * (1 - fee_rate)
rush_premium(job) = job.amount * job.rush_rate
floor_at(value, minimum) = MAX(value, minimum)
same_shape(values) = MAP(values, value => value)
billed_total(jobs) = REDUCE(0, jobs, (acc, job) => acc + job.amount)

# Inputs
A1 IS percentage = 12pct
A2 IS currency = 400

# Job ledger: open record rows, so extra fields stay welcome
Jobs = [
  { client: "Meridian", amount: 5200, rush_rate: 0.25 },
  { client: "Bluefin", amount: 3100, rush_rate: 0 },
  { client: "Harbor", amount: 7400, rush_rate: 0.1 }
]

# Polymorphic reuse: each call instantiates a fresh scheme
B1 = identity(42)
B2 = identity("invoice-run")

# Direct calls against scalars and object literals
C1 IS currency = net_of_fee(5200, A1)
C2 IS currency = rush_premium({ amount: 7400, rush_rate: 0.1, note: "expedited" })
C3 IS currency = floor_at(C1 - 6000, 0)

# Composing named functions with lambdas
D1 = MAP(Jobs, job => net_of_fee(job.amount, A1))
D2 = MAP(Jobs, job => rush_premium(job))
D3 IS currency = billed_total(Jobs)
D4 IS currency = REDUCE(0, D2, (acc, value) => acc + value)
D5 = MAP(D1, value => floor_at(value - A2, 0))

# Collection protocols: same_shape accepts any Mappable constructor
H1 = same_shape([10, 20, 30])
H2 = same_shape(Jobs)

# Summary
L1 IS currency = D3 * (1 - A1) + D4
L2 = L1 > 12000 THEN "healthy-month" ELSE "lean-month"
L3 = TEXT(L1, "0.00")
L4 = `net={L3} status={L2}`

END MODEL