Documentation
¶
Index ¶
- func MultiPusher[V any](pushers ...func(V) bool) func(v V) bool
- func MultiPusher2[K, V any](pushers ...func(K, V) bool) func(k K, v V) bool
- func Push[V any](seq iter.Seq[V], f ...func(V) bool) bool
- func Push2[K, V any](seq iter.Seq2[K, V], f ...func(K, V) bool) bool
- func TeeSeq[V any](pusher func(v V) bool, seq iter.Seq[V]) iter.Seq[V]
- func TeeSeq2[K, V any](pusher func(K, V) bool, seq iter.Seq2[K, V]) iter.Seq2[K, V]
- type Pipe
- type Pipe2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultiPusher ¶ added in v0.0.18
MultiPusher is iter.Seq equivalent of io.MultiWriter.
func MultiPusher2 ¶ added in v0.0.18
MultiPusher2 is iter.Seq2 equivalent of io.MultiWriter.
func TeeSeq ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.