collector multimethod

Methods

collector(al:ArrLike, body:Fun) Source: stdlib.ngs:1536
Defines collector { ... collect(...) ... } behaviour for ArrLike. Very similar to collector for Arr. See collector(Arr,Fun).
collector(s:Set, body:Fun) Source: stdlib.ngs:1780
Defines collector { ... collect(...) ... } behaviour for Set.
collector(a:Arr, body:Fun) Source: stdlib.ngs:2299
Defines collector { ... collect(...) ... } behaviour for arrays

Parameters

aInitial array
bodyThe 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]
collector(h:Hash, body:Fun) Source: stdlib.ngs:2313
Defines collector { ... collect(...) ... } behaviour for hashes

Parameters

hInitial hash
bodyThe body after collector keyword and initial value, wrapped in a function "collector/{'my': 'hash'} THIS_CODE"

Returns

Constructed array

Example

arr = [{"Name": "n1", "Value": "v1"},{"Name": "n2", "Value": "v2"}]
my_hash = collector/{}
	arr.each(F(elt) collect(elt.Name, elt.Value))
echo(my_hash)  # Outputs: {n1=v1, n2=v2}
collector(n:Int, body:Fun) Source: stdlib.ngs:2324
Defines collector { ... collect(...) ... } behaviour for integers (summarizes collected items).

Parameters

nInitial number
bodyThe body after collector keyword and initial value, wrapped in a function "collector/100 THIS_CODE"

Returns

Constructed array

Example

collector/0 { (1...10).each(collect) }  # 55
collector(s:Str, body:Fun) Source: stdlib.ngs:2334
EXPERIMENTAL! Do not use!
collector(s:Stats, body:Fun) Source: stdlib.ngs:4791
Undocumented