https://github.com/capturecontext/swift-result-builders
Set of general-purpose result builders
https://github.com/capturecontext/swift-result-builders
array array-builder declarative-programming result-builder resultbuilder swift
Last synced: about 2 months ago
JSON representation
Set of general-purpose result builders
- Host: GitHub
- URL: https://github.com/capturecontext/swift-result-builders
- Owner: CaptureContext
- License: mit
- Created: 2025-07-28T14:21:42.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-07-28T14:22:16.000Z (2 months ago)
- Last Synced: 2025-08-10T11:51:13.061Z (about 2 months ago)
- Topics: array, array-builder, declarative-programming, result-builder, resultbuilder, swift
- Language: Swift
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swift-result-builders
[](https://swift.org/download/)  [](https://twitter.com/capture_context)
## Products
- **[ArrayBuilder](./Sources/ArrayBuilder)**
## Usage
### ArrayBuilder
Create initializers for your own collections, here is an example of `IdentifiedArray` extension for [`swift-identified-collections`](https://github.com/pointfreeco/swift-identified-collections)
```swift
import IdentifiedCollections
import ArrayBuilderextension IdentifiedArray {
@inlinable
public init(
id: KeyPath,
@ArrayBuilder uniqueElements: () -> [Element]
) {
self.init(id: id, uniqueElements: uniqueElements())
}
}extension IdentifiedArray where Element: Identifiable, ID == Element.ID {
@inlinable
public init(
@ArrayBuilder uniqueElements: () -> [Element]
) {
self.init(uniqueElements: uniqueElements())
}
}func example(all: Bool) {
IdentifiedArray(id: \.self) {
if all {
"all"
} else {
"some"
}
"values"
"are"
"here"
}
}
```Array initializer is provided by default
```swift
[1,2,3,4,5,6,7] == Array {
1
2
[3, 4]
[[5], [6, 7]]
}
```See more examples in [`Tests`](./Tests/ArrayBuilderTests/ArrayBuilderTests.swift)
## Installation
### Basic
You can add swift-result-builders to an Xcode project by adding it as a package dependency.
1. From the **File** menu, select **Swift Packages › Add Package Dependency…**
2. Enter [`"https://github.com/capturecontext/swift-result-builders"`](https://github.com/capturecontext/swift-result-builders) into the package repository URL text field
3. Choose products you need to link them to your project.### Recommended
If you use SwiftPM for your project structure, add DeclarativeConfiguration to your package file.
```swift
.package(
url: "git@github.com:capturecontext/swift-result-builders.git",
.upToNextMinor(from: "0.0.1")
)
```
or via HTTPS```swift
.package(
url: "https://github.com:capturecontext/swift-result-builders.git",
.upToNextMinor(from: "0.0.1")
)
```Do not forget about target dependencies:
```swift
.product(
name: "ArrayBuilder",
package: "swift-result-builders"
)
```## License
This library is released under the MIT license. See [LICENSE](./LICENSE) for details.