Reference · Lists
drop
drop(list | str | null, int) -> list | strWhat it does
The list without its first n items, or the string without its first n characters,
as a new value. Dropping more than there is gives an empty one. null counts as an
empty list and gives [].
A negative n counts as 0, unlike slice, so a count worked out by subtraction stays safe.
Examples
print(drop([1, 2, 3], 2))print(drop("hello", 2))print(drop(["header", "row 1", "row 2"], 1))[3]llo["row 1", "row 2"]Edge cases
nat or past the length gives[]or"", not an error.0or a negativengives the whole value.- A string is cut by character, not by byte.
drop(null, n)is[].drop(xs, n)isslice(xs, n).
print(drop([1, 2, 3], 10), drop([1, 2], 0), drop([1, 2], -1))print(drop("añb", 2), drop("hi", 5) == "", drop("", 1) == "")print(drop(null, 2), drop([1, 2, 3], 1) == slice([1, 2, 3], 1))[] [1, 2] [1, 2]b true true[] trueErrors
A first argument that is not a list, a string or null, or a count that is not an
int, is a runtime error, not an error value. The count is required.
print(drop({ a: 1 }, 1))line 1: `drop` expects a list as argument 1, got mapprint(drop([1, 2]))line 1: `drop` expects an int as argument 2, got nothingChaining
In a pipeline the list comes first and the count is the only argument:
xs | drop(n). With take it pages through a list; after a
sort it skips the smallest.
let page = 2let size = 3print(range(10) | drop((page - 1) * size) | take(size))print([5, 3, 9, 1] | sort | drop(1))print("id-42" | drop(3) | int)[3, 4, 5][3, 5, 9]42See also
Thread 0 posts
On drop(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo