Skip to content

Commit 43432e0

Browse files
committed
Clean up generic signatures (#1143)
1 parent 3473d9b commit 43432e0

24 files changed

+518
-528
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension Effect where Error == Never {
2323
public static func keyFrames(
2424
values: [(output: Value, duration: TimeInterval)],
2525
scheduler: DateScheduler
26-
) -> Effect {
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
@@ -13,7 +13,7 @@ private let readMe = """
1313
extension Reducer {
1414
static func subscriptions(
1515
_ subscriptions: @escaping (State, Environment) -> [AnyHashable: Effect<Action, Never>]
16-
) -> Reducer {
16+
) -> Self {
1717
var activeSubscriptions: [AnyHashable: Effect<Action, Never>] = [:]
1818

1919
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
@@ -16,11 +16,11 @@ private let readMe = """
1616

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension Reducer {
5353
state: WritableKeyPath<State, DownloadComponentState<ID>>,
5454
action: CasePath<Action, DownloadComponentAction>,
5555
environment: @escaping (Environment) -> DownloadComponentEnvironment
56-
) -> Reducer {
56+
) -> Self {
5757
.combine(
5858
Reducer<DownloadComponentState<ID>, DownloadComponentAction, DownloadComponentEnvironment> {
5959
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
@@ -21,7 +21,7 @@ private let readMe = """
2121

2222
// MARK: - Favorite domain
2323

24-
struct FavoriteState<ID>: Equatable, Identifiable where ID: Hashable {
24+
struct FavoriteState<ID: Hashable>: Equatable, Identifiable {
2525
var alert: AlertState<FavoriteAction>?
2626
let id: ID
2727
var isFavorite: Bool
@@ -39,7 +39,7 @@ struct FavoriteEnvironment<ID> {
3939
}
4040

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

@@ -53,11 +53,11 @@ struct FavoriteError: Equatable, Error, Identifiable {
5353

5454
extension Reducer {
5555
/// Enhances a reducer with favoriting logic.
56-
func favorite<ID>(
56+
func favorite<ID: Hashable>(
5757
state: WritableKeyPath<State, FavoriteState<ID>>,
5858
action: CasePath<Action, FavoriteAction>,
5959
environment: @escaping (Environment) -> FavoriteEnvironment<ID>
60-
) -> Reducer where ID: Hashable {
60+
) -> Self {
6161
.combine(
6262
self,
6363
Reducer<FavoriteState<ID>, FavoriteAction, FavoriteEnvironment> {
@@ -91,7 +91,7 @@ extension Reducer {
9191
}
9292
}
9393

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

9797
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: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public typealias Effect<Value, Error: Swift.Error> = SignalProducer<Value, Error
1616
extension Effect {
1717
/// An effect that does nothing and completes immediately. Useful for situations where you must
1818
/// return an effect, but you don't need to do anything.
19-
public static var none: Effect {
19+
public static var none: Self {
2020
.empty
2121
}
2222

@@ -28,19 +28,17 @@ extension Effect {
2828
///
2929
/// - Parameter work: A closure encapsulating some work to execute in the real world.
3030
/// - Returns: An effect.
31-
public static func fireAndForget(_ work: @escaping () throws -> Void) -> Effect {
31+
public static func fireAndForget(_ work: @escaping () throws -> Void) -> Self {
3232
.deferred { () -> SignalProducer<Value, Error> in
3333
try? work()
3434
return .empty
3535
}
3636
}
3737

38-
/// Concatenates a variadic list of effects together into a single effect, which runs the effects
39-
/// one after the other.
4038
///
4139
/// - Parameter effects: A variadic list of effects.
4240
/// - Returns: A new effect
43-
public static func concatenate(_ effects: Effect...) -> Effect {
41+
public static func concatenate(_ effects: Effect...) -> Self {
4442
.concatenate(effects)
4543
}
4644

@@ -66,7 +64,7 @@ extension Effect {
6664
/// the supplied closure to create a new ``Effect``, whose values
6765
/// are then sent to the subscriber of this effect.
6866
public static func deferred(_ createProducer: @escaping () -> SignalProducer<Value, Error>)
69-
-> SignalProducer<Value, Error>
67+
-> Self
7068
{
7169
Effect<Void, Error>(value: ())
7270
.flatMap(.merge, createProducer)
@@ -103,7 +101,7 @@ extension Effect {
103101
/// used to feed it `Result<Output, Failure>` values.
104102
public static func future(
105103
_ attemptToFulfill: @escaping (@escaping (Result<Value, Error>) -> Void) -> Void
106-
) -> Effect {
104+
) -> Self {
107105
SignalProducer { observer, _ in
108106
attemptToFulfill { result in
109107
switch result {

Sources/ComposableArchitecture/Effects/Cancellation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension Effect {
3939
/// - cancelInFlight: Determines if any in-flight effect with the same identifier should be
4040
/// canceled before starting this new one.
4141
/// - Returns: A new effect that is capable of being canceled by an identifier.
42-
public func cancellable(id: AnyHashable, cancelInFlight: Bool = false) -> Effect {
42+
public func cancellable(id: AnyHashable, cancelInFlight: Bool = false) -> Self {
4343
Effect.deferred { () -> SignalProducer<Value, Error> in
4444
cancellablesLock.lock()
4545
defer { cancellablesLock.unlock() }
@@ -100,7 +100,7 @@ extension Effect {
100100
/// - cancelInFlight: Determines if any in-flight effect with the same identifier should be
101101
/// canceled before starting this new one.
102102
/// - Returns: A new effect that is capable of being canceled by an identifier.
103-
public func cancellable(id: Any.Type, cancelInFlight: Bool = false) -> Effect {
103+
public func cancellable(id: Any.Type, cancelInFlight: Bool = false) -> Self {
104104
self.cancellable(id: ObjectIdentifier(id), cancelInFlight: cancelInFlight)
105105
}
106106

@@ -109,7 +109,7 @@ extension Effect {
109109
/// - Parameter id: An effect identifier.
110110
/// - Returns: A new effect that will cancel any currently in-flight effect with the given
111111
/// identifier.
112-
public static func cancel(id: AnyHashable) -> Effect {
112+
public static func cancel(id: AnyHashable) -> Self {
113113
.fireAndForget {
114114
cancellablesLock.sync {
115115
cancellationCancellables[.init(id: id)]?.forEach { $0.dispose() }
@@ -125,7 +125,7 @@ extension Effect {
125125
/// - Parameter id: A unique type identifying the effect.
126126
/// - Returns: A new effect that will cancel any currently in-flight effect with the given
127127
/// identifier.
128-
public static func cancel(id: Any.Type) -> Effect {
128+
public static func cancel(id: Any.Type) -> Self {
129129
.cancel(id: ObjectIdentifier(id))
130130
}
131131

@@ -134,7 +134,7 @@ extension Effect {
134134
/// - Parameter ids: An array of effect identifiers.
135135
/// - Returns: A new effect that will cancel any currently in-flight effects with the given
136136
/// identifiers.
137-
public static func cancel(ids: [AnyHashable]) -> Effect {
137+
public static func cancel(ids: [AnyHashable]) -> Self {
138138
.merge(ids.map(Effect.cancel(id:)))
139139
}
140140

@@ -146,7 +146,7 @@ extension Effect {
146146
/// - Parameter ids: An array of unique types identifying the effects.
147147
/// - Returns: A new effect that will cancel any currently in-flight effects with the given
148148
/// identifiers.
149-
public static func cancel(ids: [Any.Type]) -> Effect {
149+
public static func cancel(ids: [Any.Type]) -> Self {
150150
.merge(ids.map(Effect.cancel(id:)))
151151
}
152152
}

0 commit comments

Comments
 (0)