Skip to content

Commit 42af3e3

Browse files
committed
Generic typealias Signal.Event.Transformation.
1 parent 6feb366 commit 42af3e3

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Sources/Event.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ extension Signal.Event: EventProtocol {
180180
}
181181

182182
extension Signal.Event {
183-
internal static func filter(_ isIncluded: @escaping (Value) -> Bool) -> (@escaping Signal<Value, Error>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void {
183+
internal typealias Transformation<U, E: Swift.Error> = (@escaping Signal<U, E>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void
184+
185+
internal static func filter(_ isIncluded: @escaping (Value) -> Bool) -> Transformation<Value, Error> {
184186
return { action in
185187
return { event in
186188
switch event {
@@ -202,7 +204,7 @@ extension Signal.Event {
202204
}
203205
}
204206

205-
internal static func filterMap<U>(_ transform: @escaping (Value) -> U?) -> (@escaping Signal<U, Error>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void {
207+
internal static func filterMap<U>(_ transform: @escaping (Value) -> U?) -> Transformation<U, Error> {
206208
return { action in
207209
return { event in
208210
switch event {
@@ -224,7 +226,7 @@ extension Signal.Event {
224226
}
225227
}
226228

227-
internal static func map<U>(_ transform: @escaping (Value) -> U) -> (@escaping Signal<U, Error>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void {
229+
internal static func map<U>(_ transform: @escaping (Value) -> U) -> Transformation<U, Error> {
228230
return { action in
229231
return { event in
230232
switch event {
@@ -244,7 +246,7 @@ extension Signal.Event {
244246
}
245247
}
246248

247-
internal static func mapError<E>(_ transform: @escaping (Error) -> E) -> (@escaping Signal<Value, E>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void {
249+
internal static func mapError<E>(_ transform: @escaping (Error) -> E) -> Transformation<Value, E> {
248250
return { action in
249251
return { event in
250252
switch event {
@@ -264,7 +266,7 @@ extension Signal.Event {
264266
}
265267
}
266268

267-
internal static func take(first count: Int) -> (@escaping Signal<Value, Error>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void {
269+
internal static func take(first count: Int) -> Transformation<Value, Error> {
268270
assert(count >= 1)
269271

270272
return { action in

Sources/Observer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension Signal {
3535
/// upstream.
3636
internal init<U, E: Swift.Error>(
3737
_ observer: Signal<U, E>.Observer,
38-
_ transform: @escaping (@escaping Signal<U, E>.Observer.Action) -> Action,
38+
_ transform: @escaping Event.Transformation<U, E>,
3939
_ disposable: Disposable
4040
) {
4141
var hasDeliveredTerminalEvent = false

Sources/Signal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ extension Signal {
537537
/// closure.
538538
///
539539
/// - returns: A signal that forwards events yielded by the action.
540-
internal func flatMapEvent<U, E>(_ transform: @escaping (@escaping Signal<U, E>.Observer.Action) -> (Event) -> Void) -> Signal<U, E> {
540+
internal func flatMapEvent<U, E>(_ transform: @escaping Event.Transformation<U, E>) -> Signal<U, E> {
541541
return Signal<U, E> { observer in
542542
return self.observe(.init(observer, transform, NopDisposable.shared))
543543
}

Sources/SignalProducer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ internal class SignalProducerCore<Value, Error: Swift.Error> {
272272
/// closure.
273273
///
274274
/// - returns: A producer that forwards events yielded by the action.
275-
internal func flatMapEvent<U, E>(_ transform: @escaping (@escaping Signal<U, E>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void) -> SignalProducer<U, E> {
275+
internal func flatMapEvent<U, E>(_ transform: @escaping Signal<Value, Error>.Event.Transformation<U, E>) -> SignalProducer<U, E> {
276276
return SignalProducer<U, E>(TransformerCore(source: self, transform: transform))
277277
}
278278
}
@@ -316,9 +316,9 @@ private final class SignalCore<Value, Error: Swift.Error>: SignalProducerCore<Va
316316
/// - note: This core does not use `Signal` unless it is requested via `makeInstance()`.
317317
private final class TransformerCore<Value, Error: Swift.Error, SourceValue, SourceError: Swift.Error>: SignalProducerCore<Value, Error> {
318318
private let source: SignalProducerCore<SourceValue, SourceError>
319-
private let transform: (@escaping Signal<Value, Error>.Observer.Action) -> (Signal<SourceValue, SourceError>.Event) -> Void
319+
private let transform: Signal<SourceValue, SourceError>.Event.Transformation<Value, Error>
320320

321-
init(source: SignalProducerCore<SourceValue, SourceError>, transform: @escaping (@escaping Signal<Value, Error>.Observer.Action) -> (Signal<SourceValue, SourceError>.Event) -> Void) {
321+
init(source: SignalProducerCore<SourceValue, SourceError>, transform: @escaping Signal<SourceValue, SourceError>.Event.Transformation<Value, Error>) {
322322
self.source = source
323323
self.transform = transform
324324
}
@@ -327,7 +327,7 @@ private final class TransformerCore<Value, Error: Swift.Error, SourceValue, Sour
327327
return source.start { Signal.Observer(generator($0), transform, $0) }
328328
}
329329

330-
internal override func flatMapEvent<U, E>(_ transform: @escaping (@escaping Signal<U, E>.Observer.Action) -> (Signal<Value, Error>.Event) -> Void) -> SignalProducer<U, E> {
330+
internal override func flatMapEvent<U, E>(_ transform: @escaping Signal<Value, Error>.Event.Transformation<U, E>) -> SignalProducer<U, E> {
331331
return SignalProducer<U, E>(TransformerCore<U, E, SourceValue, SourceError>(source: source) { [innerTransform = self.transform] action in
332332
return innerTransform(transform(action))
333333
})

0 commit comments

Comments
 (0)