limit multimethod
Methods
- limit(a:Arr, l:Int) Source: stdlib.ngs:2008
Truncate an array if necessary so it would have maximum l elements. Parameters
a Array to (possibly) truncate. l Maximum elements Returns
Either a or new Arr of length lExample
[10,11,12].limit(2) # [10,11] [10,11,12].limit(10) # [10,11,12]
- limit(h:Hash, l:Int) Source: stdlib.ngs:2584
Truncate a Hash if necessary so it would have maximum l key-value pairs. Parameters
h Source hash l Maximum elements Returns
HashExample
{"a": 1, "b": 2}.limit(1) # {"a": 1}
- limit(s:Str, n:Int, marker:Str='') Source: stdlib.ngs:3483
Truncate a string if necessary so it would have maximum n characters (currently bytes). Parameters
s The string to (possibly) truncate. n Maximum characters marker The truncation marker Returns
Either s or new Str of length nExample
"abc".limit(5, "...") # "abc" "abcdef".limit(5, "...") # "ab..." "abcdef".limit(2) # "ab"