Documentation ¶
Overview ¶
Package stream provides a way to construct data processing streams from smaller pieces. The design is inspired by fs2 Scala library.
Index ¶
- func AppendToSlice[A any](stm Stream[A], start []A) io.IO[[]A]
- func Collect[A any](stm Stream[A], collector func(A) error) io.IO[fun.Unit]
- func DrainAll[A any](stm Stream[A]) io.IO[fun.Unit]
- func ForEach[A any](stm Stream[A], collector func(A)) io.IO[fun.Unit]
- func Head[A any](stm Stream[A]) io.IO[A]
- func ToChannel[A any](stm Stream[A], ch chan A) io.IO[fun.Unit]
- func ToSlice[A any](stm Stream[A]) io.IO[[]A]
- type Pipe
- type Sink
- type StepResult
- type Stream
- func AddSeparatorAfterEachElement[A any](stm Stream[A], sep A) Stream[A]
- func AndThen[A any](stm1 Stream[A], stm2 Stream[A]) Stream[A]
- func AndThenLazy[A any](stm1 Stream[A], stm2 func() Stream[A]) Stream[A]
- func Drop[A any](stm Stream[A], n int) Stream[A]
- func Empty[A any]() Stream[A]
- func Eval[A any](ioa io.IO[A]) Stream[A]
- func Filter[A any](stm Stream[A], predicate func(A) bool) Stream[A]
- func FlatMap[A any, B any](stm Stream[A], f func(a A) Stream[B]) Stream[B]
- func Flatten[A any](stm Stream[Stream[A]]) Stream[A]
- func FromChannel[A any](ch chan A) Stream[A]
- func FromSideEffectfulFunction[A any](f func() (A, error)) Stream[A]
- func FromSlice[A any](as []A) Stream[A]
- func FromStepResult[A any](iosr io.IO[StepResult[A]]) Stream[A]
- func Generate[A any, S any](zero S, f func(s S) (S, A)) Stream[A]
- func Lift[A any](a A) Stream[A]
- func LiftMany[A any](as ...A) Stream[A]
- func Map[A any, B any](stm Stream[A], f func(a A) B) Stream[B]
- func MapEval[A any, B any](stm Stream[A], f func(a A) io.IO[B]) Stream[B]
- func Repeat[A any](stm Stream[A]) Stream[A]
- func StateFlatMap[A any, B any, S any](stm Stream[A], zero S, f func(a A, s S) (S, Stream[B])) Stream[B]
- func StateFlatMapWithFinish[A any, B any, S any](stm Stream[A], zero S, f func(a A, s S) (S, Stream[B]), ...) Stream[B]
- func Take[A any](stm Stream[A], n int) Stream[A]
- func Through[A any, B any](stm Stream[A], pipe Pipe[A, B]) Stream[B]
- func ToSink[A any](stm Stream[A], sink Sink[A]) Stream[fun.Unit]
- func Unfold[A any](zero A, f func(A) A) Stream[A]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendToSlice ¶
AppendToSlice executes the stream and appends it's results to the slice.
func Collect ¶ added in v0.0.10
Collect collects all element from the stream and for each element invokes the provided function
func Head ¶ added in v0.0.2
Head takes the first element and executes it. It'll fail if the stream is empty.
Types ¶
type Pipe ¶ added in v0.0.2
Pipe is a conversion of one stream to another. Technically it's a function that takes one stream and returns another.
type StepResult ¶
StepResult[A] represents the result of a single step in the step machine. It might be one of - empty, new value, or finished. The step result also returns the continuation of the stream.
func NewStepResult ¶ added in v0.0.2
func NewStepResult[A any](value A, continuation Stream[A]) StepResult[A]
NewStepResult constructs StepResult that has one value.
func NewStepResultEmpty ¶ added in v0.0.2
func NewStepResultEmpty[A any](continuation Stream[A]) StepResult[A]
NewStepResultEmpty constructs an empty StepResult.
func NewStepResultFinished ¶ added in v0.0.2
func NewStepResultFinished[A any]() StepResult[A]
NewStepResultFinished constructs a finished StepResult. The continuation will be empty as well.
type Stream ¶
type Stream[A any] io.IO[StepResult[A]]
Stream is modelled as a function that performs a single step in the state machine.
func AddSeparatorAfterEachElement ¶ added in v0.0.2
AddSeparatorAfterEachElement adds a separator after each stream element
func AndThenLazy ¶
AndThenLazy appends another stream. The other stream is constructed lazily.
func Filter ¶ added in v0.0.2
Filter leaves in the stream only the elements that satisfy the given predicate.
func Flatten ¶ added in v0.0.11
Flatten simplifies a stream of streams to just the stream of values by concatenating all inner streams.
func FromChannel ¶ added in v0.0.10
FromChannel constructs a stream that reads from the given channel until the channel is open.
func FromSideEffectfulFunction ¶ added in v0.0.3
FromSideEffectfulFunction constructs a stream from a Go-style function. It is expected that this function is not pure and can return different results.
func FromStepResult ¶ added in v0.0.10
func FromStepResult[A any](iosr io.IO[StepResult[A]]) Stream[A]
FromStepResult constructs a stream from an IO that returns StepResult.
func Generate ¶ added in v0.0.2
Generate constructs an infinite stream of values using the production function.
func StateFlatMap ¶
func StateFlatMap[A any, B any, S any](stm Stream[A], zero S, f func(a A, s S) (S, Stream[B])) Stream[B]
StateFlatMap maintains state along the way.
func StateFlatMapWithFinish ¶ added in v0.0.4
func StateFlatMapWithFinish[A any, B any, S any](stm Stream[A], zero S, f func(a A, s S) (S, Stream[B]), onFinish func(s S) Stream[B]) Stream[B]
StateFlatMapWithFinish maintains state along the way. When the source stream finishes, it invokes onFinish with the last state.
func Through ¶ added in v0.0.2
Through passes the stream data through the pipe. Technically it applies the pipe function to this stream.