Skip to content

Commit b8dddaf

Browse files
authored
Clean up generic signatures (#1143)
1 parent 2bedb4b commit b8dddaf

26 files changed

+85
-99
lines changed

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ private let readMe = """
2020
"""
2121

2222
extension Effect where Failure == Never {
23-
public static func keyFrames<S>(
23+
public static func keyFrames<S: Scheduler>(
2424
values: [(output: Output, duration: S.SchedulerTimeType.Stride)],
2525
scheduler: S
26-
) -> Effect where S: Scheduler {
26+
) -> Self {
2727
.concatenate(
2828
values
2929
.enumerated()

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ElmLikeSubscriptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private let readMe = """
1212
extension Reducer {
1313
static func subscriptions(
1414
_ subscriptions: @escaping (State, Environment) -> [AnyHashable: Effect<Action, Never>]
15-
) -> Reducer {
15+
) -> Self {
1616
var activeSubscriptions: [AnyHashable: Effect<Action, Never>] = [:]
1717

1818
return Reducer { state, _, environment in

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-Recursion.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ private let readMe = """
1515

1616
extension Reducer {
1717
static func recurse(
18-
_ reducer: @escaping (Reducer, inout State, Action, Environment) -> Effect<Action, Never>
19-
) -> Reducer {
18+
_ reducer: @escaping (Self, inout State, Action, Environment) -> Effect<Action, Never>
19+
) -> Self {
2020

21-
var `self`: Reducer!
22-
self = Reducer { state, action, environment in
21+
var `self`: Self!
22+
self = Self { state, action, environment in
2323
reducer(self, &state, action, environment)
2424
}
2525
return self

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ResuableOfflineDownloads/DownloadComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extension Reducer {
5252
state: WritableKeyPath<State, DownloadComponentState<ID>>,
5353
action: CasePath<Action, DownloadComponentAction>,
5454
environment: @escaping (Environment) -> DownloadComponentEnvironment
55-
) -> Reducer {
55+
) -> Self {
5656
.combine(
5757
Reducer<DownloadComponentState<ID>, DownloadComponentAction, DownloadComponentEnvironment> {
5858
state, action, environment in

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ReusableFavoriting.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private let readMe = """
2020

2121
// MARK: - Favorite domain
2222

23-
struct FavoriteState<ID>: Equatable, Identifiable where ID: Hashable {
23+
struct FavoriteState<ID: Hashable>: Equatable, Identifiable {
2424
var alert: AlertState<FavoriteAction>?
2525
let id: ID
2626
var isFavorite: Bool
@@ -38,7 +38,7 @@ struct FavoriteEnvironment<ID> {
3838
}
3939

4040
/// A cancellation token that cancels in-flight favoriting requests.
41-
struct FavoriteCancelId<ID>: Hashable where ID: Hashable {
41+
struct FavoriteCancelId<ID: Hashable>: Hashable {
4242
var id: ID
4343
}
4444

@@ -52,11 +52,11 @@ struct FavoriteError: Equatable, Error, Identifiable {
5252

5353
extension Reducer {
5454
/// Enhances a reducer with favoriting logic.
55-
func favorite<ID>(
55+
func favorite<ID: Hashable>(
5656
state: WritableKeyPath<State, FavoriteState<ID>>,
5757
action: CasePath<Action, FavoriteAction>,
5858
environment: @escaping (Environment) -> FavoriteEnvironment<ID>
59-
) -> Reducer where ID: Hashable {
59+
) -> Self {
6060
.combine(
6161
self,
6262
Reducer<FavoriteState<ID>, FavoriteAction, FavoriteEnvironment> {
@@ -90,7 +90,7 @@ extension Reducer {
9090
}
9191
}
9292

93-
struct FavoriteButton<ID>: View where ID: Hashable {
93+
struct FavoriteButton<ID: Hashable>: View {
9494
let store: Store<FavoriteState<ID>, FavoriteAction>
9595

9696
var body: some View {

Examples/CaseStudies/SwiftUICaseStudies/Internal/UIViewRepresented.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
struct UIViewRepresented<UIViewType>: UIViewRepresentable where UIViewType: UIView {
3+
struct UIViewRepresented<UIViewType: UIView>: UIViewRepresentable {
44
let makeUIView: (Context) -> UIViewType
55
let updateUIView: (UIViewType, Context) -> Void = { _, _ in }
66

Examples/CaseStudies/UIKitCaseStudies/Internal/UIViewRepresented.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
struct UIViewRepresented<UIViewType>: UIViewRepresentable where UIViewType: UIView {
3+
struct UIViewRepresented<UIViewType: UIView>: UIViewRepresentable {
44
let makeUIView: (Context) -> UIViewType
55
let updateUIView: (UIViewType, Context) -> Void = { _, _ in }
66

Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension Reducer {
4646
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
4747
DebugEnvironment()
4848
}
49-
) -> Reducer {
49+
) -> Self {
5050
self.debug(
5151
prefix,
5252
state: { $0 },
@@ -73,7 +73,7 @@ extension Reducer {
7373
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
7474
DebugEnvironment()
7575
}
76-
) -> Reducer {
76+
) -> Self {
7777
self.debug(
7878
prefix,
7979
state: { _ in () },
@@ -104,7 +104,7 @@ extension Reducer {
104104
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
105105
DebugEnvironment()
106106
}
107-
) -> Reducer {
107+
) -> Self {
108108
#if DEBUG
109109
return .init { state, action, environment in
110110
let previousState = toLocalState(state)

Sources/ComposableArchitecture/Effect.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public struct Effect<Output, Failure: Error>: Publisher {
4141
self.upstream = publisher.eraseToAnyPublisher()
4242
}
4343

44-
public func receive<S>(
44+
public func receive<S: Combine.Subscriber>(
4545
subscriber: S
46-
) where S: Combine.Subscriber, Failure == S.Failure, Output == S.Input {
46+
) where S.Input == Output, S.Failure == Failure {
4747
self.upstream.subscribe(subscriber)
4848
}
4949

@@ -71,7 +71,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
7171

7272
/// An effect that does nothing and completes immediately. Useful for situations where you must
7373
/// return an effect, but you don't need to do anything.
74-
public static var none: Effect {
74+
public static var none: Self {
7575
Empty(completeImmediately: true).eraseToEffect()
7676
}
7777

@@ -109,7 +109,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
109109
/// used to feed it `Result<Output, Failure>` values.
110110
public static func future(
111111
_ attemptToFulfill: @escaping (@escaping (Result<Output, Failure>) -> Void) -> Void
112-
) -> Effect {
112+
) -> Self {
113113
Deferred { Future(attemptToFulfill) }.eraseToEffect()
114114
}
115115

@@ -193,7 +193,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
193193
///
194194
/// - Parameter effects: A variadic list of effects.
195195
/// - Returns: A new effect
196-
public static func concatenate(_ effects: Effect...) -> Effect {
196+
public static func concatenate(_ effects: Self...) -> Self {
197197
.concatenate(effects)
198198
}
199199

@@ -208,9 +208,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
208208
///
209209
/// - Parameter effects: A collection of effects.
210210
/// - Returns: A new effect
211-
public static func concatenate<C: Collection>(
212-
_ effects: C
213-
) -> Effect where C.Element == Effect {
211+
public static func concatenate<C: Collection>(_ effects: C) -> Self where C.Element == Effect {
214212
guard let first = effects.first else { return .none }
215213

216214
return
@@ -226,9 +224,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
226224
///
227225
/// - Parameter effects: A list of effects.
228226
/// - Returns: A new effect
229-
public static func merge(
230-
_ effects: Effect...
231-
) -> Effect {
227+
public static func merge(_ effects: Self...) -> Self {
232228
.merge(effects)
233229
}
234230

@@ -237,7 +233,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
237233
///
238234
/// - Parameter effects: A sequence of effects.
239235
/// - Returns: A new effect
240-
public static func merge<S: Sequence>(_ effects: S) -> Effect where S.Element == Effect {
236+
public static func merge<S: Sequence>(_ effects: S) -> Self where S.Element == Effect {
241237
Publishers.MergeMany(effects).eraseToEffect()
242238
}
243239

@@ -246,7 +242,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
246242
///
247243
/// - Parameter work: A closure encapsulating some work to execute in the real world.
248244
/// - Returns: An effect.
249-
public static func fireAndForget(_ work: @escaping () throws -> Void) -> Effect {
245+
public static func fireAndForget(_ work: @escaping () throws -> Void) -> Self {
250246
// NB: Ideally we'd return a `Deferred` wrapping an `Empty(completeImmediately: true)`, but
251247
// due to a bug in iOS 13.2 that publisher will never complete. The bug was fixed in
252248
// iOS 13.3, but to remain compatible with iOS 13.2 and higher we need to do a little

Sources/ComposableArchitecture/Effects/Cancellation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension Effect {
2929
/// - cancelInFlight: Determines if any in-flight effect with the same identifier should be
3030
/// canceled before starting this new one.
3131
/// - Returns: A new effect that is capable of being canceled by an identifier.
32-
public func cancellable(id: AnyHashable, cancelInFlight: Bool = false) -> Effect {
32+
public func cancellable(id: AnyHashable, cancelInFlight: Bool = false) -> Self {
3333
Deferred {
3434
()
3535
-> Publishers.HandleEvents<
@@ -83,7 +83,7 @@ extension Effect {
8383
/// - cancelInFlight: Determines if any in-flight effect with the same identifier should be
8484
/// canceled before starting this new one.
8585
/// - Returns: A new effect that is capable of being canceled by an identifier.
86-
public func cancellable(id: Any.Type, cancelInFlight: Bool = false) -> Effect {
86+
public func cancellable(id: Any.Type, cancelInFlight: Bool = false) -> Self {
8787
self.cancellable(id: ObjectIdentifier(id), cancelInFlight: cancelInFlight)
8888
}
8989

@@ -92,7 +92,7 @@ extension Effect {
9292
/// - Parameter id: An effect identifier.
9393
/// - Returns: A new effect that will cancel any currently in-flight effect with the given
9494
/// identifier.
95-
public static func cancel(id: AnyHashable) -> Effect {
95+
public static func cancel(id: AnyHashable) -> Self {
9696
.fireAndForget {
9797
cancellablesLock.sync {
9898
cancellationCancellables[.init(id: id)]?.forEach { $0.cancel() }
@@ -108,7 +108,7 @@ extension Effect {
108108
/// - Parameter id: A unique type identifying the effect.
109109
/// - Returns: A new effect that will cancel any currently in-flight effect with the given
110110
/// identifier.
111-
public static func cancel(id: Any.Type) -> Effect {
111+
public static func cancel(id: Any.Type) -> Self {
112112
.cancel(id: ObjectIdentifier(id))
113113
}
114114

@@ -117,7 +117,7 @@ extension Effect {
117117
/// - Parameter ids: An array of effect identifiers.
118118
/// - Returns: A new effect that will cancel any currently in-flight effects with the given
119119
/// identifiers.
120-
public static func cancel(ids: [AnyHashable]) -> Effect {
120+
public static func cancel(ids: [AnyHashable]) -> Self {
121121
.merge(ids.map(Effect.cancel(id:)))
122122
}
123123

@@ -129,7 +129,7 @@ extension Effect {
129129
/// - Parameter ids: An array of unique types identifying the effects.
130130
/// - Returns: A new effect that will cancel any currently in-flight effects with the given
131131
/// identifiers.
132-
public static func cancel(ids: [Any.Type]) -> Effect {
132+
public static func cancel(ids: [Any.Type]) -> Self {
133133
.merge(ids.map(Effect.cancel(id:)))
134134
}
135135
}

0 commit comments

Comments
 (0)