{"id":20545495,"url":"https://github.com/eonist/parallelloop","last_synced_at":"2025-04-14T10:12:09.770Z","repository":{"id":93635118,"uuid":"280661241","full_name":"eonist/ParallelLoop","owner":"eonist","description":"💞 Parallel + functional operations in swift","archived":false,"fork":false,"pushed_at":"2024-07-21T11:30:01.000Z","size":38,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-27T23:24:47.759Z","etag":null,"topics":["concurrency","functional","functional-programming","parallel"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eonist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-18T13:23:39.000Z","updated_at":"2024-07-21T11:30:04.000Z","dependencies_parsed_at":"2023-06-18T14:43:54.280Z","dependency_job_id":null,"html_url":"https://github.com/eonist/ParallelLoop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonist%2FParallelLoop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonist%2FParallelLoop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonist%2FParallelLoop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonist%2FParallelLoop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eonist","download_url":"https://codeload.github.com/eonist/ParallelLoop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860190,"owners_count":21173342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","functional","functional-programming","parallel"],"created_at":"2024-11-16T01:52:25.973Z","updated_at":"2025-04-14T10:12:09.745Z","avatar_url":"https://github.com/eonist.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Tests](https://github.com/light-stream/ParallelLoop/workflows/Tests/badge.svg)\n[![codebeat badge](https://codebeat.co/badges/f8a6bae6-963e-4589-9b72-d451356b733d)](https://codebeat.co/projects/github-com-eonist-parallelloop-master)\n\n# ParallelLoop 💞\n\n\u003e Parallel + functional operations in swift\n\n### Features:\n- 👯‍♂️ Process data in parallel over many cpu-cores and awaits\n- 💜 Functional operations you already know and love\n- ⚛️ Thread safe values across cpu-cores with AtomicValue\n- ⏩ Easily stride big data-sets with the array divide operation\n- 🎚Toggle concurrency on / off \n\n### Examples:\n```swift\n// Parallel map\nlet result = [0, 1, 2, 3].concurrentMap { i in\n   i * 2\n}\nprint(result) // 0, 2, 4, 6\n\n// Parallel forEach\n[1, 2, 3, 4].concurrentForEach {\n   print($0) // 1,2,3,4\n}\n\n// Parallel compactMap\nlet array = [0, 1, nil, 3].concurrentCompactMap { i in\n   i * 2\n}\nprint(array) // 0, 2, 6\n\n// Parallel reduce\nlet str: String = [0, 1, 2].concurrentReduce(\"\") {\n   $0 + \"\\( $1)\"\n} // \"012\"\nprint(str)\n\n// Atomic value:\nlet x: Atomic\u003cInt\u003e = .init(0) // can be written and read across cores and threads\nDispatchQueue.concurrentPerform(iterations: 1000) { y in\n   x.mutate { $0 += 1 }\n}\nprint(x.value) // 1000\n\n// Stride concurrent operations on big data sets\n// We stride to utlize cores better\n// The cost of managing threads out way the benefit on big data sets\nlet batches = Array(0..\u003c1000).divideBy(by: 20) // try different amounts\nbatches.concurrentForEach { batch in // one batch at the time (50 times), avoids cpu admin overhead\n   batch.forEach { $0 } // only assigns 20 operations at the time\n} // Use .flatMap { $0 } if you need to flatten the result etc\n\n// or even easier:\n// The batches method also ensures a good distribution for big and small data sets\n// great when the data-set count varies\nArray(0..\u003c1000).batches(spread: 20).concurrentForEach { batch in\n   batch.forEach { $0 }\n}\n\n// Another example using flatMap:\nlet values: [Int] = Array(0..\u003c1000).batches(spread: 20).concurrentFlatMap { batch in\n   batch.map { $0 }\n}\n```\n\n### Installation:\n- Swift packag manager: `.package(url: \"https://github.com/passbook/ParallelLoop.git\", .branch(\"master\"))`\n- XCode package-manager: search for `ParallelLoop`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonist%2Fparallelloop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feonist%2Fparallelloop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonist%2Fparallelloop/lists"}