-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend AsyncSequence with forEach function (#17)
- Loading branch information
Showing
2 changed files
with
18 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// AsyncSequence+Stream.swift | ||
// Later | ||
// | ||
// Created by Leif on 8/8/24. | ||
// | ||
|
||
extension AsyncSequence { | ||
/// Executes a given task for each value emitted by the stream. | ||
/// - Parameter task: The task to be executed for each value. | ||
public func forEach( | ||
do task: @escaping (Element) async throws -> Void | ||
) async throws { | ||
for try await value in self { | ||
try await task(value) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters