Skip to content

Commit

Permalink
Add Collector type
Browse files Browse the repository at this point in the history
  • Loading branch information
Primetalk committed Aug 19, 2022
1 parent 295ffa5 commit 538a04e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions stream/execution.go
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/primetalk/goio/io"
)

// Collector reads the stream and produces some value.
type Collector[A any, B any] func(Stream[A]) io.IO[B]

// Collect collects all element from the stream and for each element invokes
// the provided function
func Collect[A any](stm Stream[A], collector func(A) error) io.IO[fun.Unit] {
Expand Down Expand Up @@ -87,8 +90,8 @@ func Head[A any](stm Stream[A]) io.IO[A] {
// Partition divides the stream into two that are handled independently.
func Partition[A any, C any, D any](stm Stream[A],
predicate func(A) bool,
trueHandler func(Stream[A]) io.IO[C],
falseHandler func(Stream[A]) io.IO[D],
trueHandler Collector[A, C],
falseHandler Collector[A, D],
) io.IO[fun.Pair[C, D]] {
eithersIO := FanOut(stm,
func(stm Stream[A]) io.IO[either.Either[C, D]] {
Expand Down

0 comments on commit 538a04e

Please sign in to comment.