You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Concurrency Utilities/ReactiveCollection.swift
+63-18Lines changed: 63 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -42,15 +42,14 @@ public final class IteratorSeededPublisher<S, O>: IteratorPublisherClassBase<O>
42
42
///
43
43
/// - parameters:
44
44
/// - qos: Quality of service for the dispatch queue used to sequence items and produce items in the background (default `DispatchQOS.default`).
45
-
/// - bufferSize: This is a standard argument to Reactive Stream types, in this case the argument doesn't define the buffer size but rather the number of items produced before testing for subscription cancellation (default `ReactiveStreams.defaultBufferSize`).
46
45
/// - initialSeed: The value of the seed at the start of each iteration cycle.
47
46
/// - nextItem: A closure that produces the next item, or `nil` to indicate termination, given the seed (which it can modify)
48
47
/// - seed: The seed passed to the `nextItem` closure as an `inout` parameter so that the closure can modify the seed.
@@ -76,7 +75,6 @@ public final class IteratorSeededPublisher<S, O>: IteratorPublisherClassBase<O>
76
75
///
77
76
/// - note:
78
77
/// - Each subscriber receives all of the sequence individually, i.e. each subscriber receives the whole sequence (provided that the given sequence supports multiple traversal).
79
-
/// - This class does not use buffering, because the buffer is the given sequence.
80
78
/// - When created the given sequence is copied, therefore any changes to the sequence made after the publisher is created are *not* reflected in the items produced (the copy of the sequence is made at creation time not subscription time).
81
79
///
82
80
/// - parameters
@@ -91,10 +89,9 @@ public final class ForEachPublisher<O>: IteratorPublisherClassBase<O> {
91
89
/// - parameters:
92
90
/// - sequence: The sequence of items produced (one sequence per subscription assuming that the sequence can be traversed multiple times).
93
91
/// - qos: Quality of service for the dispatch queue used to sequence items and produce items in the background (default `DispatchQOS.default`).
94
-
/// - bufferSize: This is a standard argument to Reactive Stream types, in this case the argument doesn't define the buffer size but rather the number of items produced before testing for subscription cancellation (default `ReactiveStreams.defaultBufferSize`).
@@ -184,7 +181,7 @@ public final class ReduceFutureSubscriber<T, R>: FutureSubscriberClassBase<T, R>
184
181
185
182
// MARK: `Processors`s.
186
183
187
-
/// A `Processor` that takes input items from its input subscription maps (a.k.a. processes, a.k.a. transforms) them into output items, using its seed, and outputs them and to its output subscriber (Reactive Stream version of `Sequence.map(_ transform:)`).
184
+
/// A `Processor` that takes input items from its input subscription and maps (a.k.a. processes, a.k.a. transforms) them into output items, using its seed (Reactive Stream version of `Sequence.map(_ transform:)`).
188
185
///
189
186
/// - warning:
190
187
/// - `processors`s are not thread safe, since they are an alternative to dealing with thread safety directly and therefore it makes no sense to share them between threads.
@@ -193,37 +190,85 @@ public final class ReduceFutureSubscriber<T, R>: FutureSubscriberClassBase<T, R>
193
190
///
194
191
/// - parameters
195
192
/// - S: The type of the seed accepted by the given transform closure.
196
-
/// - T: The type of the elements subscribed to.
197
-
/// - R: The result type of the accumulation.
198
-
publicfinalclassMapSeededProcessor<S, I, O>:MapProcessorClassBase<I,O>{
193
+
/// - I: The type of the input elements subscribed to.
194
+
/// - O: The output type after the mapping.
195
+
publicfinalclassMapSeededProcessor<S, I, O>:ProcessorClassBase<I,O>{
199
196
privateletinitialSeed:S
200
197
201
198
privatelettransformClosure:(inoutS,I)throws->O
202
199
203
200
privatevarseed:S
204
201
205
-
/// A `Processor` that takes input items from its input subscription maps (a.k.a. processes, a.k.a. transforms) them into output items, using its seed, and outputs them and to its output subscriber (Reactive Stream version of `Sequence.map(_ transform:)`).
202
+
/// A `Processor` that takes input items from its input subscription and maps (a.k.a. processes, a.k.a. transforms) them into output items, using its seed (Reactive Stream version of `Sequence.map(_ transform:)`).
206
203
///
207
204
/// - parameters:
208
205
/// - initialSeed: The initial value of the seed at the start of new input and output subscription.
209
-
/// - transform: The mapping/processing transform that converts an input item intop an output item.
206
+
/// - transform: The mapping/processing transform that converts an input item into an output item.
/// Resets the seed at the start of each new output subscription.
226
221
publicoverridefunc _resetOutputSubscription(){
227
222
seed = initialSeed
228
223
}
229
224
}
225
+
226
+
/// A `Processor` that takes input items from its input subscription and maps (a.k.a. processes, a.k.a. transforms) them into *non-`nil`* output items (Reactive Stream version of `Sequence.flatMap(_ transform:)`).
227
+
///
228
+
/// - warning:
229
+
/// - `processors`s are not thread safe, since they are an alternative to dealing with thread safety directly and therefore it makes no sense to share them between threads.
230
+
/// - There are *no* `Publisher` methods/properties intended for use by a client (the programmer using an instance of this class), the client *only* passes the instance to the `subscribe` method of a `Publisher`.
231
+
/// Passing the instance to the publisher is best accomplished using operator `~~>`, since this emphasizes that the other methods are not for client use.
232
+
///
233
+
/// - parameters
234
+
/// - S: The type of the seed accepted by the given transform closure.
235
+
/// - I: The type of the input elements subscribed to.
236
+
/// - O: The output type after the mapping.
237
+
publicfinalclassFlatMapSeededProcessor<S, I, O>:ProcessorClassBase<I,O>{
238
+
privateletinitialSeed:S
239
+
240
+
privatelettransformClosure:(inoutS,I)throws->O?
241
+
242
+
privatevarseed:S
243
+
244
+
/// A `Processor` that takes input items from its input subscription and maps (a.k.a. processes, a.k.a. transforms) them into *non-`nil`* output items (Reactive Stream version of `Sequence.flatMap(_ transform:)`).
245
+
///
246
+
/// - parameters:
247
+
/// - initialSeed: The initial value of the seed at the start of new input and output subscription.
248
+
/// - transform:
249
+
/// The mapping/processing transform that converts an input item into an *optional* output item.
250
+
/// If the transformed/mapped/processed item is `nil`, it is disguarded.
/// Calls the transform closure with the seed and the given input item and passes the resulting transformed item onto the output susbcription assuming that it isn't `nil`, if it is `nil` it requests an extra input item.
258
+
///
259
+
/// - parameter inputItem: The input item to be transformed/mapped/processed.
0 commit comments