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))
| 12 | // |
| 13 | // See the package documentation for more information on non-blocking unordered functions and error handling. |
| 14 | func 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]. |
| 30 | func OrderedMap[A, B any](in <-chan Try[A], n int, f func(A) (B, error)) <-chan Try[B] { |