-
Notifications
You must be signed in to change notification settings - Fork 157
De-duplicate isBeta
logic
#1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||||||||||
/* | ||||||||||||||
This source file is part of the Swift.org open source project | ||||||||||||||
|
||||||||||||||
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors | ||||||||||||||
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors | ||||||||||||||
Licensed under Apache License v2.0 with Runtime Library Exception | ||||||||||||||
|
||||||||||||||
See https://swift.org/LICENSE.txt for license information | ||||||||||||||
|
@@ -163,3 +163,27 @@ public struct AvailabilityRenderItem: Codable, Hashable, Equatable { | |||||||||||||
self.isBeta = isBeta | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
extension Array where Array.Element == AvailabilityRenderItem { | ||||||||||||||
/// Determines whether all platforms in the array are in beta. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a verb phrase ("determines") but properties is more commonly described by nouns. We could either change this to a function (
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That said, with a simple and clean name like |
||||||||||||||
/// | ||||||||||||||
/// This property returns `true` if every availability item in the array has its `isBeta` property set to `true`, | ||||||||||||||
/// indicating that the symbol is introduced in a beta version across all platforms. If the array is empty, | ||||||||||||||
/// this property returns `false`, as an item with no platform availability information is not considered | ||||||||||||||
/// to be in beta. | ||||||||||||||
Comment on lines
+170
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this behavior is clarified in the API then this documentation can be simplified to only covering the empty behavior. Also, there's no need to wrap documentation to a fixed column width.
Suggested change
|
||||||||||||||
/// | ||||||||||||||
/// This computed property centralizes the beta determination logic to avoid code duplication across multiple | ||||||||||||||
/// components that need to check whether a symbol is in beta based on its platform availability. | ||||||||||||||
/// `NavigatorIndexableRenderMetadataRepresentation`, `OutOfProcessReferenceResolver.ResolvedInformation` and `LinkDestinationSummary` all store an array of ``AvailabilityRenderItem`` and need to determine beta status based on platform availability, | ||||||||||||||
/// so it is convenient to de-duplicate the shared logic here. | ||||||||||||||
Comment on lines
+175
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type of comment is about the implementation and isn't all that relevant to the user of the API.
Suggested change
|
||||||||||||||
/// | ||||||||||||||
/// - Returns: `true` if all platforms in the array are in beta; `false` if the array is empty or if any | ||||||||||||||
/// platform is not in beta. | ||||||||||||||
Comment on lines
+179
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple properties like this one don't need a returns section.
Suggested change
|
||||||||||||||
var isBeta: Bool { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this name looks a bit strange at the call site because the array isn't "in beta" rather it's the containing elements that are. Also, this name has some ambiguity as to what it means for a collection of platforms to be in beta. This is explained in the documentation but if this behavior was clarified in the symbol name it would avoid this ambiguity all together.
Suggested change
|
||||||||||||||
guard !self.isEmpty else { | ||||||||||||||
return false | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return self.allSatisfy { $0.isBeta == true } | ||||||||||||||
Comment on lines
+183
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: you can write this in a single expression as
Suggested change
|
||||||||||||||
} | ||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIY: this can be expressed more simply as