take for filters

Take only the first n elements of a list, or the first n bytes of a binary value.

Signature

> take (n)

Parameters

  • n: starting from the front, the number of elements to return

Input/output types:

inputoutput
binarybinary
list<any>list<any>
rangelist<number>
tabletable

Examples

Return the first item of a list/table

> [1 2 3] | take 1
╭───┬───╮
│ 01 │
╰───┴───╯

Return the first 2 items of a list/table

> [1 2 3] | take 2
╭───┬───╮
│ 01 │
│ 12 │
╰───┴───╯

Return the first two rows of a table

> [[editions]; [2015] [2018] [2021]] | take 2
╭───┬──────────╮
│ # │ editions │
├───┼──────────┤
│ 02015 │
│ 12018 │
╰───┴──────────╯

Return the first 2 bytes of a binary value

> 0x[01 23 45] | take 2
Length: 2 (0x2) bytes | printable whitespace ascii_other non_ascii
00000000:   01 23#

Return the first 3 elements of a range

> 1..10 | take 3
╭───┬───╮
│ 01 │
│ 12 │
│ 23 │
╰───┴───╯

Subcommands:

nametypeusage
take untilBuiltinTake elements of the input until a predicate is true.
take whileBuiltinTake elements of the input while a predicate is true.