|
1 | | -extension Array { |
2 | | - /// Create a ``ForkedArray`` from the current `Array` |
| 1 | +extension Sequence { |
| 2 | + /// Create a ``ForkedArray`` from the current `Sequence` |
3 | 3 | public func fork<Output>( |
4 | 4 | filter: @escaping (Element) async throws -> Bool, |
5 | 5 | map: @escaping (Element) async throws -> Output |
6 | 6 | ) -> ForkedArray<Element, Output> { |
7 | 7 | ForkedArray( |
8 | | - self, |
| 8 | + Array(self), |
9 | 9 | filter: filter, |
10 | 10 | map: map |
11 | 11 | ) |
12 | 12 | } |
13 | 13 |
|
14 | | - /// Create a ``ForkedArray`` from the current `Array` |
| 14 | + /// Create a ``ForkedArray`` from the current `Sequence` |
15 | 15 | public func fork<Output>( |
16 | 16 | map: @escaping (Element) async throws -> Output |
17 | 17 | ) -> ForkedArray<Element, Output> { |
18 | 18 | fork(filter: { _ in true }, map: map) |
19 | 19 | } |
20 | 20 |
|
21 | | - /// Create a ``ForkedArray`` from the current `Array` and get the Output Array |
| 21 | + /// Create a ``ForkedArray`` from the current `Sequence` and get the Output Array |
22 | 22 | public func forked<Output>( |
23 | 23 | filter: @escaping (Element) async throws -> Bool, |
24 | 24 | map: @escaping (Element) async throws -> Output |
25 | 25 | ) async throws -> [Output] { |
26 | | - try await ForkedArray( |
27 | | - self, |
28 | | - filter: filter, |
29 | | - map: map |
30 | | - ) |
31 | | - .output() |
| 26 | + try await fork(filter: filter, map: map).output() |
32 | 27 | } |
33 | 28 |
|
34 | | - /// Create a ``ForkedArray`` from the current `Array` and get the Output Array |
| 29 | + /// Create a ``ForkedArray`` from the current `Sequence` and get the Output Array |
35 | 30 | public func forked<Output>( |
36 | 31 | map: @escaping (Element) async throws -> Output |
37 | 32 | ) async throws -> [Output] { |
@@ -59,7 +54,7 @@ extension Array { |
59 | 54 | try await fork(filter: isIncluded, map: identity).output() |
60 | 55 | } |
61 | 56 |
|
62 | | - /// Calls the given closure for each of the elements in the Array. This function uses ``ForkedArray`` and will be parallelized when possible. |
| 57 | + /// Calls the given closure for each of the elements in the Sequence. This function uses ``ForkedArray`` and will be parallelized when possible. |
63 | 58 | public func asyncForEach( |
64 | 59 | _ transform: @escaping (Element) async throws -> Void |
65 | 60 | ) async throws { |
|
0 commit comments