Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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:

inputoutput
binarylist<binary>
list<any>list<list<any>>
tablelist<table>

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.