add skip/2 as the counterpart to limit/2 (#3181)
I also changed the behavior of limit/2 with negative count to emit an error, like nth/2 does. Also, I redefined nth/2 using skip/2 to minimize the impact of growth of builtin filters.
This commit is contained in:
1 parent
860af44fee
commit
1bebd23aad
5 files changed
+70
-13
No files matched your search
@@ -334,6 +334,30 @@ null
|
||||
"badness"
|
||||
[1]
|
||||
|
||||
try limit(-1; error) catch .
|
||||
null
|
||||
"limit doesn't support negative count"
|
||||
|
||||
[skip(3; .[])]
|
||||
[1,2,3,4,5,6,7,8,9]
|
||||
[4,5,6,7,8,9]
|
||||
|
||||
[skip(0,2,3,4; .[])]
|
||||
[1,2,3]
|
||||
[1,2,3,3]
|
||||
|
||||
[skip(3; .[])]
|
||||
[]
|
||||
[]
|
||||
|
||||
try skip(-1; error) catch .
|
||||
null
|
||||
"skip doesn't support negative count"
|
||||
|
||||
nth(1; 0,1,error("foo"))
|
||||
null
|
||||
1
|
||||
|
||||
[first(range(.)), last(range(.))]
|
||||
10
|
||||
[0,9]
|
||||
|
||||
Generated
+5
-1
@@ -873,10 +873,14 @@ isempty(.[])
|
||||
[1,2,3]
|
||||
false
|
||||
|
||||
[limit(3;.[])]
|
||||
[limit(3; .[])]
|
||||
[0,1,2,3,4,5,6,7,8,9]
|
||||
[0,1,2]
|
||||
|
||||
[skip(3; .[])]
|
||||
[0,1,2,3,4,5,6,7,8,9]
|
||||
[3,4,5,6,7,8,9]
|
||||
|
||||
[first(range(.)), last(range(.)), nth(./2; range(.))]
|
||||
10
|
||||
[0,9,5]
|
||||
|
||||
Reference in new issue
Block a user