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

Function Map

transform.go:14–27  ·  view source on GitHub ↗

Map takes a stream of items of type A and transforms them into items of type B using a function f. Returns a new stream of transformed items. This is a non-blocking unordered function that processes items concurrently using n goroutines. An ordered version of this function, [OrderedMap], is also av

(in <-chan Try[A], n int, f func(A) (B, error))

Source from the content-addressed store, hash-verified

12//
13// See the package documentation for more information on non-blocking unordered functions and error handling.
14func Map[A, B any](in <-chan Try[A], n int, f func(A) (B, error)) <-chan Try[B] {
15 return core.FilterMap(in, n, func(a Try[A]) (Try[B], bool) {
16 if a.Error != nil {
17 return Try[B]{Error: a.Error}, true
18 }
19
20 b, err := f(a.Value)
21 if err != nil {
22 return Try[B]{Error: err}, true
23 }
24
25 return Try[B]{Value: b}, true
26 })
27}
28
29// OrderedMap is the ordered version of [Map].
30func OrderedMap[A, B any](in <-chan Try[A], n int, f func(A) (B, error)) <-chan Try[B] {

Callers 12

ExampleFromSeqFunction · 0.92
ExampleFromSeq2Function · 0.92
ExampleToSeq2Function · 0.92
ExampleFunction · 0.92
Example_batchingFunction · 0.92
Example_fanIn_FanOutFunction · 0.92
CheckAllUsersExistFunction · 0.92
ExampleCatchFunction · 0.92
ExampleErrFunction · 0.92
ExampleMapFunction · 0.92
BenchmarkMapAndDrainFunction · 0.85
universalMapFunction · 0.85

Calls 1

FilterMapFunction · 0.92

Tested by 12

ExampleFromSeqFunction · 0.74
ExampleFromSeq2Function · 0.74
ExampleToSeq2Function · 0.74
ExampleFunction · 0.74
Example_batchingFunction · 0.74
Example_fanIn_FanOutFunction · 0.74
CheckAllUsersExistFunction · 0.74
ExampleCatchFunction · 0.74
ExampleErrFunction · 0.74
ExampleMapFunction · 0.74
BenchmarkMapAndDrainFunction · 0.68
universalMapFunction · 0.68