Skip to content

Instantly share code, notes, and snippets.

View insightmind's full-sized avatar
👨‍💻
Developing iOS Apps

Niklas Bülow insightmind

👨‍💻
Developing iOS Apps
View GitHub Profile
@DougGregor
DougGregor / parallel_map.swift
Created December 24, 2020 01:10
Swift async/await implementation of a parallel map
extension Collection {
func parallelMap<T>(
parallelism requestedParallelism: Int? = nil,
_ transform: @escaping (Element) async throws -> T
) async throws -> [T] {
let defaultParallelism = 2
let parallelism = requestedParallelism ?? defaultParallelism
let n = self.count
if n == 0 {