Skip to content

Releases: swift-primitives/swift-builder-primitives

Release 0.1.0: DictionaryBuilder and ArrayBuilder Modernization

Choose a tag to compare

@coenttb coenttb released this 30 Jul 06:42

✨ New Features

DictionaryBuilder

Complete result builder for type-safe dictionary construction with:

  • Tuple syntax: ("key", "value") for simple key-value pairs
  • KeyValuePair helper: KeyValuePair("key", "value") for better readability
  • Dictionary merging: Seamlessly merge existing dictionaries
  • Full control flow: Support for if/else, loops, and optionals
  • Key conflict resolution: "Last writer wins" semantics
  • Type safety: Generic <Key: Hashable, Value> with full type inference
let config = Dictionary<String, String> {
    ("host", "localhost")
    ("port", "8080")
    if enableSSL {
        ("ssl", "true")
        ("cert_path", "/path/to/cert.pem")
    }
    existingConfig // merge existing dictionary
}

🔄 Improvements

ArrayBuilder Modernization

Updated to use modern buildPartialBlock methods:

  • Better performance: More efficient compilation and runtime
  • Consistent architecture: Aligns with other builders in the package
  • Hybrid approach: Combines buildPartialBlock efficiency with buildExpression type safety
  • Full compatibility: All existing code continues to work unchanged

📚 Documentation

  • Comprehensive README updates with DictionaryBuilder examples
  • Real-world usage patterns including Dynamic Configuration System example
  • Updated architecture documentation showing all five builders
  • Production-ready examples for common use cases

🧪 Testing

  • 112 comprehensive tests covering all builders and edge cases
  • Full test coverage for DictionaryBuilder functionality
  • Verified compatibility - all existing functionality preserved
  • Performance testing with large datasets

🏗️ Complete Architecture

swift-builders now provides a complete result builder ecosystem:

swift-builders
    ├── ArrayBuilder        → Generic array construction (modernized)
    ├── DictionaryBuilder   → Key-value pair construction (new)
    ├── SetBuilder          → Unique element collections
    ├── StringBuilder       → Text content generation
    └── MarkdownBuilder     → Documentation and markup

🚀 Getting Started

Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/coenttb/swift-builders.git", from: "0.1.0")
]

Quick Example

import ArrayBuilder
import DictionaryBuilder
import SetBuilder

// Build arrays declaratively
let menuItems = Array<String> {
    "Home"
    "About"
    if user.isAuthenticated {
        "Dashboard"
        "Profile" 
    }
}

// Create configuration dictionaries
let serverConfig = Dictionary<String, String> {
    ("host", "localhost")
    ("port", "8080")
    if isProduction {
        ("ssl", "true")
    }
}

// Build unique collections
let permissions = Set<Permission> {
    .read
    .write
    if user.isAdmin {
        [.admin, .delete]
    }
}

🎯 What's Next

This release completes the core collection builder suite. Future releases will focus on:

  • Performance optimizations
  • Additional convenience methods
  • Enhanced error handling
  • More real-world examples

💬 Support


Full Changelog: 0.0.1...0.1.0

Swift Builders 0.0.1

Choose a tag to compare

@coenttb coenttb released this 29 Jul 14:10

Swift Builders 0.0.1

Initial release of Swift Result Builders for collections and strings.

Features

  • ArrayBuilder: Type-safe array construction with control flow support
  • SetBuilder: Set construction with duplicate handling and array support
  • StringBuilder: String building with newline joining
  • MarkdownBuilder: Markdown document construction with formatting options

Capabilities

  • Full result builder protocol support (conditionals, loops, optionals)
  • Performance optimized implementations
  • Comprehensive test coverage
  • Swift Package Manager integration with individual library products
  • Clean API with proper disambiguation
  • Minimal dependencies (no Foundation imports)

Package Products

Import the unified library or individual components:

// All builders
.product(name: "Builders", package: "swift-builders")

// Individual builders
.product(name: "ArrayBuilder", package: "swift-builders")
.product(name: "SetBuilder", package: "swift-builders") 
.product(name: "StringBuilder", package: "swift-builders")
.product(name: "MarkdownBuilder", package: "swift-builders")

Usage

// Array building
let numbers = Array<Int> {
    1
    2
    if condition { 3 }
}

// String building (default)
let text = String {
    "Line 1"
    "Line 2"
}

// Markdown building
let doc = String(markdown: {
    "# Title"
    "Content"
})

// Set building
let tags = Set<String> {
    "swift"
    ["ios", "mobile"]
}

This provides a foundation for declarative collection and string building in Swift applications.