peek

For default.

Peek the first <n> elements of a stream and store them in the metadata.

Command Type

built-in

Signature

> peek {flags} (n)

Parameters

  • n: Number of elements to peek, if the input is a stream or list.

Input/output types:

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

Examples

Peek the first 2 elements of a stream.

> seq 1 5 | peek 2 | metadata | $in.peek
╭────────┬───────────╮
│ type   │ list      │
│ stream │ true      │
│        │ ╭───┬───╮ │
│ value  │ │ 0 │ 1 │ │
│        │ │ 1 │ 2 │ │
│        │ ╰───┴───╯ │
╰────────┴───────────╯

Lists can also be peeked.

> [1, 2, 3] | peek 1 | metadata | $in.peek
╭────────┬───────────╮
│ type   │ list      │
│ stream │ false     │
│        │ ╭───┬───╮ │
│ value  │ │ 0 │ 1 │ │
│        │ ╰───┴───╯ │
╰────────┴───────────╯

Peeking non-list values won’t return any values.

> 'hello' | peek 1 | metadata | $in.peek
╭────────┬────────╮
│ type   │ string │
│ stream │ false  │
╰────────┴────────╯

Peeking non-list streams (text streams, binary streams, external byte streams) won’t return any values.

> [0x[11] 0x[13 15]] | bytes collect | peek | metadata | $in.peek
╭────────┬────────╮
│ type   │ binary │
│ stream │ true   │
╰────────┴────────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.