Streams

A stream produces a sequence of typed values asynchronously using yield.

Declaration

cleat
stream tokens(prompt: string) -> string
    needs { llm }
    buffer: 16
{
    yield "hello "
    yield "world"
}

Clauses

ClauseRequiredDescription
needs { ... }noEffect requirements
buffer:yesGo channel buffer size

Producing values

Use yield inside a stream body to emit values:

cleat
stream countdown(n: int) -> int
    buffer: 8
{
    for i in range(n, 0) {
        yield i
    }
}

Consuming streams

Use for...in to iterate over stream values:

cleat
for token in llm.tokens("Tell me about Cleat") {
    io.print(token)
}
io.println("")  // final newline

The loop runs until the stream body completes, at which point the channel is closed and the loop exits.

How it works

Edit this page on GitHub