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

peek for default

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

Signature

> peek {flags} (n)

Parameters

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

Input/output types:

inputoutput
list<any>list<any>
tabletable
anyany

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   │ value │
│ 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   │
╰────────┴────────╯