Spec-Zone.ru › Nushell

chunks for filters

Divide a list, table or binary input into chunks of `chunk_size`.

Signature

> chunks {flags} (chunk_size)

Parameters

  • chunk_size: The size of each chunk.

Input/output types:

input output
table list<table>
list<any> list<list<any>>
binary list<binary>

Examples

Chunk a list into pairs

> [1 2 3 4] | chunks 2
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ │ 1 │ 2 │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ 3 │ │
│   │ │ 1 │ 4 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

Chunk the rows of a table into triplets

> [[foo bar]; [0 1] [2 3] [4 5] [6 7] [8 9]] | chunks 3
╭───┬───────────────────╮
│ 0 │ ╭───┬─────┬─────╮ │
│   │ │ # │ foo │ bar │ │
│   │ ├───┼─────┼─────┤ │
│   │ │ 0 │   0 │   1 │ │
│   │ │ 1 │   2 │   3 │ │
│   │ │ 2 │   4 │   5 │ │
│   │ ╰───┴─────┴─────╯ │
│ 1 │ ╭───┬─────┬─────╮ │
│   │ │ # │ foo │ bar │ │
│   │ ├───┼─────┼─────┤ │
│   │ │ 0 │   6 │   7 │ │
│   │ │ 1 │   8 │   9 │ │
│   │ ╰───┴─────┴─────╯ │
╰───┴───────────────────╯

Chunk the bytes of a binary into triplets

> 0x[11 22 33 44 55 66 77 88] | chunks 3
╭───┬───────────────╮
│ 0 │ [17, 34, 51]  │
│ 1 │ [68, 85, 102] │
│ 2 │ [119, 136]    │
╰───┴───────────────╯

Notes

This command will error if chunk_size is negative or zero.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/chunks.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API