Methods

collectorΒΆ

collector(a:Arr, body:Fun)

Defines collector { ... collect(...) ... } behaviour for arrays
Source: stdlib.ngs:828

a

Initial array

body

The body after collector keyword and possible initial value, wrapped in a function "collector THIS_CODE" or "collector/my_init THIS_CODE"

Returns

Constructed array

Example

items = collector {
  collect(10)
  for(i;2) collect(i)
  collect(20)
}
echo(items)  # Outputs: [10,0,1,20]

# Or start with few items:
items = collector/[100,200] {
  collect(10)
  for(i;2) collect(i)
  collect(20)
}
echo(items)  # Outputs: [100,200,10,0,1,20]