Home Explore Blog CI



nushell

commands/docs/chunks.md
52796db44ed4a79f02b6836345419b1c5e2c5d0f5168e3a60000000300000a35
---
title: chunks
categories: |
  filters
version: 0.104.0
filters: |
  Divide a list, table or binary input into chunks of `chunk_size`.
usage: |
  Divide a list, table or binary input into chunks of `chunk_size`.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `chunks` for [filters](/commands/categories/filters.md)

<div class='command-title'>Divide a list, table or binary input into chunks of `chunk_size`.</div>

## Signature

```> chunks {flags} (chunk_size)```

## Parameters

 -  `chunk_size`: The size of each chunk.


## Input/output types:

| input     | output          |
| --------- | --------------- |
| binary    | list\<binary\>    |
| list\<any\> | list\<list\<any\>\> |
| table     | list\<table\>     |
## Examples

Chunk a list into pairs
```nu
> [1 2 3 4] | chunks 2
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ │ 1 │ 2 │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ 3 │ │
│   │ │ 1 │ 4 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

```

Chunk the rows of a table into triplets
```nu
> [[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
```nu
> 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.

Chunks
664e7fb2 (1st chunk of `commands/docs/chunks.md`)
Title: chunks command
Summary
The `chunks` command divides a list, table, or binary input into chunks of a specified size. It takes the `chunk_size` as an argument and returns a list of lists, a list of tables, or a list of binaries, depending on the input type. The command will error if `chunk_size` is negative or zero.