notes.md (1491B)
@(expr)
-------
Evaluate `expr` once per element, with . bound to the current element.
```
Examples:
int[] doubled(int[] xs) =
xs | @(. * 2)
str[] labels(Reading[] rows) =
rows | @("high" if .value > 100.0 else "normal")
```
Masking or filtering
---------------------
Masking/filtering works as you would expect at first, then evolves into something more like APL.
It's best to call `[]` the Selector.
```
xs[i] // scalar index
xs[is] // gather by int[] indices
xs[mask] // compress by bool[] mask
```
`xs[3]` returns the 4th element
`xs[[0 2]]` returns the first and 3rd element
`xs[0..-1]` returns the range from the 1st, to the one before last
`xs[[true, false, true]]` returns the mask against the collection, in this case 1st and 3rd.
Selectors can also be using expression to filter collections
`integer_list[. > 0]` returns values higher than 0
`rows[.valid]` within a struct, invoke valid(element) on each element
Implied self
------------
`.` is `self` within the context, it's the current subject.
Inside a free function it's implied the first argument.
`float len(Vec2) = math.sqrt(.x ^ 2 + .y ^ 2)`
is equivalent to
`float len(Vec2 v) = math.sqrt(v.x ^ 2 + v.y ^2)`
inside a method of a struct, it's implied to this struct subject
```
struct Vec2 ::
float x, y
float len() = math.sqrt(.x ^ 2 + .y ^2)
```
Inside a selector, map, or other collection expr, `.` refers to the current element.
`rows[valid]`