.nib std
nib 0.3.1-pre

Pre-release documentation. This describes nib 0.3.1-pre, which is on main and has no release yet: what it documents beyond 0.3.0 may change before it ships.

module always in scope

Record

A record like another with some fields replaced, written #{ r with field: value }.

#{ r with role: "leader", term: 3 } is the record r with role and term replaced and every other field as it was. r is not changed: records are values, and this is a new one. Each replaced field must be one r has, holding a value of the type r already gives it, and the answer has r's own type, so a data record stays that data.

let n = #{ role: "follower", term: 1, votes: 0 };
let p = #{ n with role: "leader", term: 2 };
(n.role, p.role, p.term, p.votes)
("follower", "leader", 2, 0)

Functions

funcupdate
Record.update :: r: 'r, fields: #{…} -> 'r

The long spelling of #{ r with … }: Record.update(r, #{role: "leader"}) is the same expression, and the compiler reads the short one into it. A field the record does not have is a type error that names the fields it does have.

Record.update(#{ a: 1, b: 2 }, #{ b: 20 })
#{a: 1, b: 20}