Record Patterns & Projections
Record patterns destructure values by field name. This page covers the full range of record destructuring forms, including dotted paths and projection expressions.
Basic record patterns
Match a record and bind its fields to names:
type Profile = {
name: Text,
score: Int
}
type Profile -> Text
func greet =
||> { name } -> "Hello, {name}!"You can bind multiple fields in one pattern:
type Profile -> Text
func summary =
||> { name, score } -> "{name} scored {score}"See Pattern Matching for full pattern syntax including tuples, constructors, and wildcards.
Dotted path destructuring
When a record contains nested records, dotted paths reach into the structure without writing nested patterns manually:
type City = {
name: Text,
population: Int
}
type Address = {
city: City,
street: Text
}
type User = {
name: Text,
address: Address
}
value user : User = {
name: "Ada",
address: {
city: {
name: "London",
population: 8982000
},
street: "St James's Square"
}
}
type User -> Text
func cityName =
||> { address.city.name } -> name{ address.city.name } is sugar for nested patterns:
type User -> Text
func cityNameExpanded = user => user
||> { address: { city: { name } } } -> nameThe leaf segment (name) becomes the bound variable. This works at any depth:
type User -> Text
func streetName =
||> { address.street } -> streetYou can combine dotted paths with ordinary fields:
type User -> Text
func userCity =
||> { name, address.city.name: cityName } -> "{name} lives in {cityName}"Here address.city.name: cityName renames the bound variable to cityName instead of the default leaf name.
Record projection expressions
The { field: . } form extracts a field and makes it the subject for further piping. The dot (.) means "this becomes the ambient subject":
type Profile = {
name: Text,
score: Int
}
type Profile -> Bool
func isTopScore = { score: . } >= 100This is sugar for:
type Profile = {
name: Text,
score: Int
}
type Profile -> Bool
func isTopScore = profile => profile
||> { score } -> score >= 100The key insight: { field: . } is not record construction — it is a projection that extracts the named field from the input.
Dotted projection
Dotted paths combine with the projection form to reach into nested structures:
type User -> Text
func getCityName = { address.city.name: . }This extracts address.city.name from the input and makes it available for downstream pipes:
type User -> Text
func upperCityName = user =>
toUpper (getCityName user)The same dotted-path idea is also available in selected-subject function headers:
type Z = { z: Int }
type Y = { y: Z }
type X = { x: Y }
type Int -> Int
func addOne = . + 1
type X -> Int
func readNested = state { x.y.z! }
|> addOneHere { x.y.z! } means "select state.x.y.z as the subject for the continuation." It is projection sugar in the header, not a new general parameter-pattern form.
Projection in pipes
Projection expressions work naturally as pipe stages:
value uppercasedCity = user
|> { address.city.name: . }
|> toUpperChained dot projection can select the same path in one stage:
value uppercasedCityStepwise = user
|> .address.city.name
|> toUpperPatch removal
The : - syntax in a patch removes a field from a record. The result type is the input type minus the removed field:
type Full = {
name: Text,
email: Text,
debug: Bool
}
type Full -> { name: Text, email: Text }
func stripDebug = . <| { debug: - }Removal can target nested fields using selectors:
value state = { profile: { name: "Ada", debug: True }, ready: True }
value cleaned = state <| { profile.debug: - }See Values & Functions § Structural patches for more on the <| operator and patch selectors.