diff --git a/Sources/Later/Extensions/AsyncSequence+Stream.swift b/Sources/Later/Extensions/AsyncSequence+Stream.swift new file mode 100644 index 0000000..65dfdc7 --- /dev/null +++ b/Sources/Later/Extensions/AsyncSequence+Stream.swift @@ -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) + } + } +} diff --git a/Sources/Later/Stream/Stream.swift b/Sources/Later/Stream/Stream.swift index 9ed7527..c045ecc 100644 --- a/Sources/Later/Stream/Stream.swift +++ b/Sources/Later/Stream/Stream.swift @@ -43,16 +43,6 @@ final public class Stream: AsyncSequence, Sendable { self.init(emitAction: nil, didSucceed: didSucceed, didFail: didFail, task: task) } - /// 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 (Value) async throws -> Void - ) async throws { - for try await value in self { - try await task(value) - } - } - /// Transforms the values emitted by the stream using a given closure. /// - Parameter transform: The closure to transform each value. /// - Returns: A new stream with the transformed values.