Home / Learn / 10 Collections
Release v0.4.0Edition 0.2
10.10 Recap and reference
Page 11 of 11
10.10.1 For agents
Every diagnostic of Common mistakes is available as JSON with una --json check .. For a when that forgets None:
json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U2007","severity":"error","domain":"types","message":"`when` does not match variant `None` of `Option`","primary":{"file":"src/report.una","start":{"line":97,"col":3},"end":{"line":97,"col":7}},"related":[],"repairs":[{"rank":1,"escape_cost":0,"description":"add an arm for each missing variant, such as `is None`, or an `else` arm","edit":null}],"explain":"una explain U2007"}],"fixable":0}The repair of U2007 has a description and no edit, because the right arm depends on what the absence means. The U0007 of a brace in JSON text carries exact edits, which una fix . applies. The compact rule: a value from first, at, get or first_where is an Option, used through when or or_else; a call that changes a list or a map in place is written edit xs.set(...) on a let edit name; a lambda takes its types from the parameter it is passed to; map, filter, fold and first_where declare fails of their function.
10.10.2 Recap
- A list holds values of one type, from position 0.
appendandsortgive back new lists;atandfirstread one element, as anOption. for x in xsruns its body once per element, in order, and zero times for an empty list.- A function type,
fn(Int) -> Int, lets you pass a function by its name or as a lambda,fn(x) -> …, whose types come from where it is passed. - A function type without
usesorfailsis pure; a lambda may fail only for a parameter whose function declaresfails ofit. - Use
map,filter,foldandfirst_wherefor one-expression steps, andforfor longer ones. - Group with a map:
getandor_else, thenedit m.set(...). A map lists its keys in order, and its keys need an order. - Parse JSON with a clause or
attempt, read it withwhenandget, and write it withto_json.
10.10.3 Reference
- Construct pages: functions and lambdas,
for,let editandeditparameters,when,if errorandif none,example - Standard library: the prelude (
List,Option,append,set,at,first,is_empty,first_where,contains,sum,sort,map,filter,fold,or_else,min,max), maps (Map,Entry,empty_map), text (join), JSON (Json,JsonError,parse_json,to_json,quote_json) - Diagnostics: U0007, U0101, U2001, U2007, U2010, U2020, U2025, U3001, U3003, U3007, U3009
- Specification: functions and contracts (lambdas), the standard library, the memory model (
for,let edit,set), constraints on generics, maps, JSON