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: 16

Direct children types

DelimStr
EXPERIMENTAL. Delimited string. Showing ArrLike usage.

Methods

[](al:ArrLike, idx:Int) Source: stdlib.ngs:657
Set element in the underlying array.
[]=(al:ArrLike, idx:Int, x:Any) Source: stdlib.ngs:660
Get element from the underlying array.
Bool(al:ArrLike) Source: stdlib.ngs:669
Check whether al has any elements.
each(al:ArrLike, cb:Fun) Source: stdlib.ngs:666
Call cb for each element in the underlying array.
get(al:ArrLike, idx:Int, dflt:Any) Source: stdlib.ngs:663
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, field:Str='items') Source: stdlib.ngs:649
ArrLike constructor

Parameters

fieldname of the field that holds the underlying array
len(al:ArrLike) Source: stdlib.ngs:654
Get length of the underlying array.
push(al:ArrLike, val:Any) Source: stdlib.ngs:672
Push an element to the underlying array.
without(ds:ArrLike, without_elt:Any) Source: autoload/DelimStr.ngs:29
Get new DelimStr without the given element

Example

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