limit multimethod

Methods

limit(a:Arr, l:Int) Source: stdlib.ngs:2156
Truncate an array if necessary so it would have maximum l elements.

Parameters

aArray to (possibly) truncate.
lMaximum elements

Returns

Either a or new Arr of length l

Example

[10,11,12].limit(2)   # [10,11]
[10,11,12].limit(10)  # [10,11,12]
limit(h:Hash, l:Int) Source: stdlib.ngs:2723
Truncate a Hash if necessary so it would have maximum l key-value pairs.

Parameters

hSource hash
lMaximum elements

Returns

Hash

Example

{"a": 1, "b": 2}.limit(1)  # {"a": 1}
limit(s:Str, n:Int, marker:Str='') Source: stdlib.ngs:3635
Truncate a string if necessary so it would have maximum n characters (currently bytes).

Parameters

sThe string to (possibly) truncate.
nMaximum characters
markerThe truncation marker

Returns

Either s or new Str of length n

Example

"abc".limit(5, "...")     # "abc"
"abcdef".limit(5, "...")  # "ab..."
"abcdef".limit(2)         # "ab"