liveBook · Manning

Seque

As explained in Clojure: The Essential Reference

seque is a Clojure function that presents a producer sequence through an asynchronously filled in-memory queue.

seque presents a producer sequence through an asynchronously filled in-memory queue, allowing producers and consumers to run at different speeds. It returns the elements of s while buffering up to n items when consumption lags; n defaults to 100. section 9.1.4 section 9.1

The contract has two arities and several boundary conditions:

  • Use (seque s) or (seque n-or-q s); s must support the sequential interface and may be empty or nil. section 9.1.4
  • Pass a positive integer capacity or an ordered, finite BlockingQueue that accepts nil; LinkedBlockingQueue is the advised implementation. section 9.1.4
  • Expect an empty sequence for an empty or nil s, IllegalArgumentException for zero or negative n, and NullPointerException when n is nil. section 9.1.4

Decoupling a fast producer

A slow consumer can read from a buffered producer without forcing each production step to wait: (slow-consumer (seque (fast-producer 5))) produces all five values before the consumer finishes, whereas the unbuffered form alternates production and consumption.

How Clojure: The Essential Reference covers it

How deep it goes
Defines arities, queue constraints, buffering behavior, exceptions, and producer-consumer examples without exposing implementation internals.
Examples
Demonstrates fast and slow producers or consumers, filesystem scanning, explicit LinkedBlockingQueue capacity, and a sentinel-based queue analogue.
What it assumes
Assumes familiarity with Clojure sequences and sequential access, while specifying the required collection interface from the API contract.
What you can do after
Apply it via Clojure to buffer lazy producers, coordinate processing rates, and choose an integer capacity or BlockingQueue.
How it connects
Connects sequences, lazy sequences, blocking queues, parallel mapping, and producer-consumer coordination.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.