File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,53 @@ func main() {
277277</tr >
278278</table >
279279
280+ Concurrently map a slice:
281+
282+ <table >
283+ <tr >
284+ <th ><code >stdlib</code ></th >
285+ <th ><code >conc</code ></th >
286+ </tr >
287+ <tr >
288+ <td >
289+
290+ ``` go
291+ func concMap (input []int , f func (int ) int ) []int {
292+ res := make ([]int , len (input))
293+ var idx atomic.Int64
294+
295+ var wg sync.WaitGroup
296+ for i := 0 ; i < 10 ; i++ {
297+ wg.Add (1 )
298+ go func () {
299+ defer wg.Done ()
300+
301+ for {
302+ i := int (idx.Add (1 ) - 1 )
303+ if i >= len (input) {
304+ return
305+ }
306+
307+ res[i] = f (input[i])
308+ }
309+ }()
310+ }
311+ wg.Wait ()
312+ return res
313+ }
314+ ```
315+ </td >
316+ <td >
317+
318+ ``` go
319+ func concMap (input []int , f func (int ) int ) []int {
320+ iter.Map (input, f)
321+ }
322+ ```
323+ </td >
324+ </tr >
325+ </table >
326+
280327Process an ordered stream concurrently:
281328
282329
You can’t perform that action at this time.
0 commit comments