Skip to content

Go package for operating on streams of elements

License

Notifications You must be signed in to change notification settings

blizzy78/gostreams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9845fe0 · Apr 3, 2024

History

43 Commits
Apr 3, 2024
Apr 21, 2023
Apr 3, 2024
Apr 3, 2024
Apr 3, 2024
Sep 30, 2023
Jul 20, 2023
May 12, 2023
Apr 21, 2023
May 12, 2023
Apr 3, 2024
Apr 3, 2024
Apr 3, 2024
Aug 8, 2023
Apr 21, 2023
Apr 3, 2024
Sep 30, 2023
Apr 3, 2024
Jul 18, 2023
Apr 3, 2024
Aug 8, 2023
Jul 22, 2023
Apr 3, 2024
Apr 3, 2024

Repository files navigation

GoDoc

gostreams

A Go package that provides a set of operations on streams of elements.

import "github.com/blizzy78/gostreams"

Code example

// construct a producer from a slice
ints := gostreams.Produce([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})

// filter for even elements
// since we only need the elements themselves, we can use FuncPredicate
ints = gostreams.Filter(ints, gostreams.FuncPredicate(func(elem int) bool {
	return elem%2 == 0
}))

// map elements by doubling them
// since we only need the elements themselves, we can use FuncMapper
ints = gostreams.Map(ints, gostreams.FuncMapper(func(elem int) int {
	return elem * 2
}))

// map elements by converting them to strings
intStrs := gostreams.Map(ints, gostreams.FuncMapper(strconv.Itoa))

// perform a reduction to collect the strings into a slice
strs, _ := gostreams.ReduceSlice(context.Background(), intStrs)

fmt.Printf("%+v\n", strs)

// Output: [4 8 12 16 20]

License

This package is licensed under the MIT license.