SwiftImpl // Add array builder and Bool.from(integer:).

This commit is contained in:
ShikiSuen 2024-02-05 23:37:26 +08:00
parent a1d9f502c1
commit 368f9bb653
1 changed files with 37 additions and 0 deletions

View File

@ -127,6 +127,10 @@ public extension Bool {
toggle() toggle()
return self return self
} }
static func from(integer: Int) -> Bool {
integer > 0 ? true : false
}
} }
// MARK: - User Defaults Storage // MARK: - User Defaults Storage
@ -342,3 +346,36 @@ public extension String {
.compare(otherVersionComponents.joined(separator: versionDelimiter), options: .numeric) // <6> .compare(otherVersionComponents.joined(separator: versionDelimiter), options: .numeric) // <6>
} }
} }
// MARK: - Array Builder.
@resultBuilder
public enum ArrayBuilder<OutputModel> {
public static func buildEither(first component: [OutputModel]) -> [OutputModel] {
component
}
public static func buildEither(second component: [OutputModel]) -> [OutputModel] {
component
}
public static func buildOptional(_ component: [OutputModel]?) -> [OutputModel] {
component ?? []
}
public static func buildExpression(_ expression: OutputModel) -> [OutputModel] {
[expression]
}
public static func buildExpression(_: ()) -> [OutputModel] {
[]
}
public static func buildBlock(_ components: [OutputModel]...) -> [OutputModel] {
components.flatMap { $0 }
}
public static func buildArray(_ components: [[OutputModel]]) -> [OutputModel] {
Array(components.joined())
}
}