MCPcopy
hub / github.com/destel/rill / FromChan

Function FromChan

wrap.go:78–98  ·  view source on GitHub ↗

FromChan converts a regular channel into a stream. Additionally, this function can take an error, that will be added to the output stream alongside the values. Either argument can be nil, in which case it is ignored. If both arguments are nil, the function returns nil. Such function signature allow

(values <-chan A, err error)

Source from the content-addressed store, hash-verified

76//
77// stream := rill.FromChan(someFunc())
78func FromChan[A any](values <-chan A, err error) <-chan Try[A] {
79 if values == nil && err == nil {
80 return nil
81 }
82
83 out := make(chan Try[A])
84 go func() {
85 defer close(out)
86
87 // error goes first
88 if err != nil {
89 out <- Try[A]{Error: err}
90 }
91
92 for x := range values {
93 out <- Try[A]{Value: x}
94 }
95 }()
96
97 return out
98}
99
100// FromChans converts a regular channel into a stream.
101// Additionally, this function can take a channel of errors, which will be added to

Callers 15

TestBatchFunction · 0.85
TestErrFunction · 0.85
TestFirstFunction · 0.85
TestForEachFunction · 0.85
TestAnyAllFunction · 0.85
TestReduceFunction · 0.85
TestMapReduceFunction · 0.85
TestSplit2Function · 0.85
TestTeeFunction · 0.85
TestFromChanFunction · 0.85
TestMapFunction · 0.85

Calls

no outgoing calls

Tested by 15

TestBatchFunction · 0.68
TestErrFunction · 0.68
TestFirstFunction · 0.68
TestForEachFunction · 0.68
TestAnyAllFunction · 0.68
TestReduceFunction · 0.68
TestMapReduceFunction · 0.68
TestSplit2Function · 0.68
TestTeeFunction · 0.68
TestFromChanFunction · 0.68
TestMapFunction · 0.68