liveBook · Manning

Peek

Peek is an operation that observes the next or otherwise accessible element without consuming, removing, or advancing past it.

How 3 Manning books explain it

Kafka Streams in Action, Second Edition

KStream.peek is a Kafka Streams operation that performs a stateless action on each record without changing the record's key or value.

How it is used
Provides development-time visibility into records without interrupting a Kafka Streams topology.
How deep it goes
Explains callback behavior, unchanged records, chaining, and windowed-result inspection without descending into processor internals.
Examples
Uses the Yelling app and windowed aggregation logging to inspect records before transformations and analyze window boundaries.
What you can do after
Apply it via Kafka Streams to print, log, or collect records while continuing a KStream chain.

Read how Kafka Streams in Action, Second Edition explains peek →

100 Java Mistakes and How to Avoid Them

A peek operation is a Stream intermediate operation that applies a supplied Consumer to elements as they pass through the pipeline without changing their values.

How it is used
Uses a Consumer for observational side effects, chiefly debugging within a Stream pipeline.
How deep it goes
Explains side effects, short-circuiting, parallel execution, and optimization limits without descending into Stream implementation internals.
Examples
Uses trimming, external collection, filtering, limit(5), count, and separate streams to expose incomplete side effects.
What you can do after
Diagnose/debug pipeline traversal with peek and replace fragile side effects using explicit stream operations.

Read how 100 Java Mistakes and How to Avoid Them explains peek →

Grokking Data Structures

A peek operation returns the top element of a stack without removing it or changing the stack's structure.

How it is used
Supports inspecting a stack’s next element without removing it or changing its structure.
How deep it goes
Explains empty checks, private-attribute access, mutable results, copying, and public accessors, then assigns implementation exercises.
Examples
Uses a pile-of-dishes analogy, Python linked-list code, deepcopy, get(i), and exercises comparing linked-list and dynamic-array stacks.
What you can do after
Build it from scratch by implementing peek, handling empty stacks, protecting mutable values, and replacing private access with get(i).

Read how Grokking Data Structures explains peek →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.