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. append and sort give back new lists; at and first read one element, as an Option.
  • for x in xs runs 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 uses or fails is pure; a lambda may fail only for a parameter whose function declares fails of it.
  • Use map, filter, fold and first_where for one-expression steps, and for for longer ones.
  • Group with a map: get and or_else, then edit m.set(...). A map lists its keys in order, and its keys need an order.
  • Parse JSON with a clause or attempt, read it with when and get, and write it with to_json.

10.10.3 Reference

Next:11 Packages and modules