ArrLike type

Parent type for user-defined types with array-like behaviour. Use in cases when you would like to inherit from built-in Arr. Inheriting from built-ins is not possible for now.

Example

type T(ArrLike)
F Str(t:T) "<My array has ${len(t)} items totalling ${sum(t)}>"  # Override one of the Arr methods
a = T()
a.push(10)
a.push(20)
echo(a)  # <My array has 2 items totalling 30>

# If you need init() you should have something like the following to allow ArrLike initialization:
init(t:T) {
	super(t)
	...
}

Direct parent types

Eachable1
Eachable which each() calls the callback with one argument
Direct subtypes: 18

Direct children types

AllOf
Should probably inherit from Set, not ArrLike.
AnyOf
Should probably inherit from Set, not ArrLike.
DelimStr
EXPERIMENTAL. Delimited string. Showing ArrLike usage.
Lines
Array of strings which comprise a text which is treated as a unit for purposes of output (and maybe for other purposes later).
Results
Results, an array-like of Result elements
Threads
Threads

Methods

.(al:ArrLike, s:Str) Source: stdlib.ngs:2092
Return array made of given field of each element of given array. Will throw KeyNotFound if any of the elements does not have the desired field. Use get() to handle missing field differently.
[](al:ArrLike, idx:Int) Source: stdlib.ngs:2060
Get element from the underlying array.
[]=(al:ArrLike, idx:Int, x:Any) Source: stdlib.ngs:2063
Set element in the underlying array.
Arr(al:ArrLike) Source: stdlib.ngs:2077
Get the underlying array of ArrLike. Not a copy.

Returns

Arr
Bool(al:ArrLike) Source: stdlib.ngs:2073
Check whether al has any elements.
collector(al:ArrLike, body:Fun) Source: stdlib.ngs:2096
Defines collector { ... collect(...) ... } behaviour for ArrLike. Very similar to collector for Arr. See collector(Arr,Fun).
each(al:ArrLike, cb:Fun) Source: stdlib.ngs:2070
Call cb for each element in the underlying array.

Returns

al
get(al:ArrLike, idx:Int, dflt:Any) Source: stdlib.ngs:2066
Get element at the given index or return dflt if the index is out of range (element at the given index does not exist). See get(Arr).
init(al:ArrLike) Source: stdlib.ngs:2036
Undocumented
init(al:ArrLike, field:Str=null) Source: stdlib.ngs:2038
Throws NotImplemented if field is specified

Parameters

fieldDEPRECATED name of the field that holds the underlying array.
init(al:ArrLike, e:Eachable1) Source: stdlib.ngs:2047
Undocumented
init(al:ArrLike, arr:Arr) Source: stdlib.ngs:2052
Undocumented
join(al:ArrLike, s:Str) Source: stdlib.ngs:2087
Join items to a single string using given separator s

Returns

Str
len(al:ArrLike) Source: stdlib.ngs:2057
Get length of the underlying array.
push(al:ArrLike, val:Any) Source: stdlib.ngs:2083
Push an element to the underlying array.
Str(a:ArrLike) Source: stdlib.ngs:2109
Convert ArrLike to a human-readable representation
without(ds:ArrLike, without_elt:Any) Source: autoload/globals/DelimStr.ngs:25
Get new DelimStr without the given element

Example

DelimStr("/bin:/usr/bin:/usr/local/bin").without("/usr/bin").Str()  # "/bin:/usr/local/bin"