streaming-patterns

Primary Primitive: iter.Seq2[T, error]

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "streaming-patterns" with this command: npx skills add lookatitude/beluga-ai/lookatitude-beluga-ai-streaming-patterns

Streaming Patterns

Primary Primitive: iter.Seq2[T, error]

func (m *Model) Stream(ctx context.Context, msgs []schema.Message) iter.Seq2[schema.StreamChunk, error] { return func(yield func(schema.StreamChunk, error) bool) { stream, err := m.client.Stream(ctx, msgs) if err != nil { yield(schema.StreamChunk{}, err); return } defer stream.Close() for { select { case <-ctx.Done(): yield(schema.StreamChunk{}, ctx.Err()); return default: } chunk, err := stream.Recv() if err == io.EOF { return } if err != nil { yield(schema.StreamChunk{}, err); return } if !yield(convertChunk(chunk), nil) { return } // consumer stopped } } }

Composition

  • Pipe: func Pipe[A, B any](first iter.Seq2[A, error], transform func(A) (B, error)) iter.Seq2[B, error]

  • Collect: Stream to slice — func Collect[T any](stream iter.Seq2[T, error]) ([]T, error)

  • Invoke from Stream: Stream, collect, return last.

  • Fan-out: iter.Pull2() to get next/stop, broadcast to N consumers.

  • BufferedStream: Channel-backed buffer for backpressure.

Rules

  • Public API: iter.Seq2[T, error] — never <-chan .

  • Internal goroutine communication: channels are fine.

  • Always check context cancellation in producers.

  • yield returning false = consumer stopped — respect immediately.

  • Use iter.Pull2 only when pull semantics are genuinely needed.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

go-framework

No summary provided by upstream source.

Repository SourceNeeds Review
General

go-interfaces

No summary provided by upstream source.

Repository SourceNeeds Review
General

provider-implementation

No summary provided by upstream source.

Repository SourceNeeds Review
General

doc-writing

No summary provided by upstream source.

Repository SourceNeeds Review