tee

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiPusher added in v0.0.18

func MultiPusher[V any](pushers ...func(V) bool) func(v V) bool

MultiPusher is iter.Seq equivalent of io.MultiWriter.

func MultiPusher2 added in v0.0.18

func MultiPusher2[K, V any](pushers ...func(K, V) bool) func(k K, v V) bool

MultiPusher2 is iter.Seq2 equivalent of io.MultiWriter.

func Push

func Push[V any](seq iter.Seq[V], f ...func(V) bool) bool

func Push2

func Push2[K, V any](seq iter.Seq2[K, V], f ...func(K, V) bool) bool

func TeeSeq

func TeeSeq[V any](pusher func(v V) bool, seq iter.Seq[V]) iter.Seq[V]

TeeSeq is iter.Seq equivalent of io.TeeReader.

TeeSeq returns a iter.Seq that pushes to pusher what it reads from seq. Yielding values from the returned iterator performs push before the inner loop receives the value. The iterator is not stateful; you may want to wrap it with iterable.Resumable. If pusher returns false, the iterator stops iteration without yielding value.

func TeeSeq2

func TeeSeq2[K, V any](pusher func(K, V) bool, seq iter.Seq2[K, V]) iter.Seq2[K, V]

TeeSeq2 is iter.Seq2 equivalent of io.TeeReader.

TeeSeq2 returns a iter.Seq2 that pushes to pusher what it reads from seq. Yielding key-value pairs from the returned iterator performs push before the inner loop receives the pair. The iterator is not stateful; you may want to wrap it with iterable.Resumable2. If pusher returns false, the iterator stops iteration without yielding pair.

Types

type Pipe

type Pipe[V any] struct {
	// contains filtered or unexported fields
}

Pipe is similar io.Pipe

func NewPipe

func NewPipe[V any](n int) *Pipe[V]

NewPipe creates new Pipe instance. Unlike io.Pipe, you can choose buffer size of internal channel by putting n. If n is less than or equal to zero, it is unbuffered.

func TeeSeqPipe

func TeeSeqPipe[V any](bufSize int, seq iter.Seq[V]) (*Pipe[V], *iterable.Resumable[V])

TeeSeqPipe tees values from seq to *Pipe. see doc comments for TeeSeq. Yielding values from returned *iterable.Resumable also performs push to *Pipe.

Closing pipe and stopping resumable are caller's responsibility.

func (*Pipe[V]) Close

func (p *Pipe[V]) Close()

Close closes p. After calling Close, all Push failes returnning false, the iterator returned from *Pipe.IntoIter stops after buffered values.

Close itself is not gorotine safe; it is safe to call Close and Push from multiple goroutines. But simultaneous multiple calls to Close may panic.

func (*Pipe[V]) IntoIter

func (p *Pipe[V]) IntoIter() iter.Seq[V]

IntoIter returns the reading side of pipe. The iterator yields values sent by *Pipe.Push. The iterator stops only after *Pipe.Close is called.

func (*Pipe[V]) Push

func (p *Pipe[V]) Push(v V) bool

Push pushes v to p. Values might queue up in buffered channel if the internal channel was buffered, and might be received by the other end of the pipe by consuming an iterator retrived from *Pipe.IntoIter.

Push may block long if values are not read from the other side of the pipe.

func (*Pipe[V]) TryPush

func (p *Pipe[V]) TryPush(v V) (open, pushed bool)

TryPush is like *Pipe.Push, but does not block on sending. If *Pipe.Close is already called, open will be false. If it would block on sending v, pushed will false.

type Pipe2

type Pipe2[K, V any] struct {
	// contains filtered or unexported fields
}

Pipes is like Pipe, but it pipes key-value pairs.

func NewPipe2

func NewPipe2[K, V any](n int) *Pipe2[K, V]

NewPipe2 creates new Pipe2 instance. Unlike io.Pipe, you can choose buffer size of internal channel by putting n. If n is less than or equal to zero, it is unbuffered.

func TeeSeqPipe2

func TeeSeqPipe2[K, V any](bufSize int, seq iter.Seq2[K, V]) (*Pipe2[K, V], *iterable.Resumable2[K, V])

TeeSeqPipe2 tees key-value pairs from seq to *Pipe2. see doc comments for TeeSeq2. Yielding pairs from returned *iterable.Resumable2 also performs push to *Pipe2.

Closing pipe and stopping resumable are caller's responsibility.

func (*Pipe2[K, V]) Close

func (p *Pipe2[K, V]) Close()

Close closes p. After calling Close, all Push fails returnning false, the iterator returned from *Pipe.IntoIter stops after buffered values.

Close itself is not gorotine safe; it is safe to call Close and Push from multiple goroutines. But simultaneous multiple calls to Close may panic.

func (*Pipe2[K, V]) IntoIter2

func (p *Pipe2[K, V]) IntoIter2() iter.Seq2[K, V]

IntoIter2 returns the reading side of pipe. The iterator yields k-v pairs sent by *Pipe.Push. The iterator stops only after *Pipe.Close is called.

func (*Pipe2[K, V]) Push

func (p *Pipe2[K, V]) Push(k K, v V) bool

Push pushes a pair of k and v to p. Pairs might queue up in buffered channel if the internal channel was buffered, and will be received by the other end of the pipe by consuming an iterator retrived from *Pipe.IntoIter.

Push may block long if values are not read from the other side of the pipe.

func (*Pipe2[K, V]) TryPush

func (p *Pipe2[K, V]) TryPush(k K, v V) (open, pushed bool)

TryPush is like *Pipe2.Push, but does not block on sending. If *Pipe.Close is already called, open will be false. If it would block on sending k adn v, pushed will false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL