Skip to content

New peek command for inspecting streams without collecting#17796

Open
Bahex wants to merge 3 commits intonushell:mainfrom
Bahex:push-xrxpvryrnszp
Open

New peek command for inspecting streams without collecting#17796
Bahex wants to merge 3 commits intonushell:mainfrom
Bahex:push-xrxpvryrnszp

Conversation

@Bahex
Copy link
Copy Markdown
Member

@Bahex Bahex commented Mar 13, 2026

peek command allows checking whether the pipeline input is a value or a stream, and accessing the first $n elements of a stream without collecting the stream.

I chose to provide the information as part of pipeline metadata rather than providing it as a closure parameter (like metadata access). While this means peek is only useful in combination metadata access, it avoids having to use nested closures when they are used together:

.. | peek 2 {|peek|
	metadata access {|metadata|
		..
	}
}
# vs
.. | peek 2 | metadata access {|metadata|
	# $metadata.peek
	..
}

Release notes summary - What our users need to know

TODO

Tasks after submitting

N/A

@Bahex Bahex added A:streaming Issues related to streaming data (or collecting data when it should be streamed) notes:additions Noted in "Additions" section A:commands General additions or changes to commands labels Mar 13, 2026
Comment thread crates/nu-command/src/filters/peek.rs
@Juhan280
Copy link
Copy Markdown
Contributor

Juhan280 commented Mar 14, 2026

Making peek entirely dependent on metadata access doesn't feel right.

Maybe peek could take an optional closure parameter? And only populate metadata if the closure is not provided? Or it could populate metadata regardless.

}

fn add_peek_metadata(
mut metadata: Option<PipelineMetadata>,
Copy link
Copy Markdown
Contributor

@Juhan280 Juhan280 Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason we are not using Option<&mut PipelineMetadata> ?

@NotTheDr01ds
Copy link
Copy Markdown
Contributor

NotTheDr01ds commented Mar 14, 2026

If peek can only be used with metadata access, is there any advantage over having it as a separate command rather than metadata access --peek?

Alternatively, can we envision a use-case (I can't at the moment) where it would be useful to have:

peek 2 {|p|
  some conditional based on peeked value {
    metadata access {
      ..
    }
  }
}

Granted, that adds two levels of nesting, and again, I'm not even sure there's a use-case.

@Bahex
Copy link
Copy Markdown
Member Author

Bahex commented Mar 16, 2026

@NotTheDr01ds I think having a separate command is better because:

  • it avoids adding flags in favor of composing commands
  • peek as a standalone command has much better discoverability. I don't think anyone would go straight for metadata access when they want to peek stream items without collecting.

@Juhan280
Copy link
Copy Markdown
Contributor

peek as a standalone command is fine. Just make it not entirely dependent on metadata access. An optional closure argument would resolve that

@Bahex Bahex force-pushed the push-xrxpvryrnszp branch from c9372fa to cfef425 Compare March 21, 2026 15:08
@Bahex Bahex closed this Mar 22, 2026
@Bahex Bahex deleted the push-xrxpvryrnszp branch March 22, 2026 11:25
@Bahex Bahex restored the push-xrxpvryrnszp branch March 22, 2026 12:07
@Bahex Bahex reopened this Mar 22, 2026
@Bahex Bahex closed this Mar 22, 2026
@Bahex Bahex deleted the push-xrxpvryrnszp branch March 22, 2026 12:08
@Bahex Bahex restored the push-xrxpvryrnszp branch March 22, 2026 12:10
@Bahex Bahex reopened this Mar 22, 2026
@Bahex Bahex force-pushed the push-xrxpvryrnszp branch from cfef425 to b23c53b Compare April 20, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:commands General additions or changes to commands A:streaming Issues related to streaming data (or collecting data when it should be streamed) notes:additions Noted in "Additions" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants