package module
v0.0.0-...-12edf05 Latest Latest

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 3 Imported by: 0



Build Status Coverage Status Go Report Card GoDoc


$ go install github.com/nmi/gostream


See stream_test.go for other functions.

// repeat: 1, 2, 3, 1, 2, 3
repeat := gostream.GenerateRepeatStream(ctx, 1, 2, 3)

// samenum: 1000, 1000, 1000, ...
samenum := gostream.GenerateRepeatStream(ctx, 1000)

// random: 3, 3843029809, 11, ... (for example)
random := gostream.GenerateRandIntsStream(ctx)


For some workloads, multiple streams run in parallel and scale with the number of CPUs.

$ for i in `seq 1 4`; do go test -bench=. -cpu=$i | grep "ns/op"; done
BenchmarkAppendStringsStream             1000000              1108 ns/op  # 1 CPU
BenchmarkAppendStringsStream-2           1000000              1439 ns/op  # 2 CPU
BenchmarkAppendStringsStream-3           1000000              1774 ns/op  # 3 CPU
BenchmarkAppendStringsStream-4           1000000              1992 ns/op  # 4 CPU



Package gostream provides utility functions for channel processing



This section is empty.


This section is empty.


func GenerateRandIntsStream

func GenerateRandIntsStream(ctx context.Context) <-chan interface{}

GenerateRandIntsStream generates a random integer sequence infinitely.

func GenerateRepeatStream

func GenerateRepeatStream(ctx context.Context, list ...interface{}) <-chan interface{}

GenerateRepeatStream generates all elemtnes of the list infinitely

func GenerateSerialIntsStream

func GenerateSerialIntsStream(ctx context.Context) <-chan interface{}

GenerateSerialIntsStream produces an infinite serial integer sequence in ascending order.

func Map

func Map(ctx context.Context,
	f func(args ...interface{}) interface{},
	inStreams ...<-chan interface{}) <-chan interface{}

Map first applies the function f to the first element of all input streams. Also, Map does the same for the second and subsequent elements.

func Merge

func Merge(ctx context.Context, inStreams ...<-chan interface{}) <-chan interface{}

Merge combines multiple streams into one stream.

func Take

func Take(ctx context.Context, inStream <-chan interface{}, num int) <-chan interface{}

Take takes the top num items from the input stream.


This section is empty.

Jump to

Keyboard shortcuts

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