swift-delta

0.5.1

Swift package for a type representing a source value, a target value, or both a source and a target value.
Formkunft/swift-delta

What's New

Swift Delta 0.5.1

2025-05-03T17:09:04Z
  • Adds subscript to access an optional element on a Delta using a Delta.Side

Swift Delta

Swift Delta is a package for a type Delta<Element> with three cases:

  • source(Element)
  • target(Element)
  • transition(source: Element, target: Element)

Description

This Delta type represents an inclusive OR relation: Either a source element is available, or a target element is available, or both are available. Delta behaves similar to Optional, but instead of representing 0 or 1 elements, it represents 1 or 2 elements.

Implementation

The source and target are described as the two sides of a delta. Both sides are accessible via optional source and target properties. Convenient methods like resolve(favoring:) and merge(coalesce:) also provide access to the elements.

Transform a Delta value to a different Delta value using map(:), asyncMap(:), mapAny(:), or mapAll(:).

The Delta type also conforms to all standard protocols (depending on the conformances of it’s Element type):

  • Equatable
  • Hashable
  • CustomDebugStringConvertible
  • Encodable
  • EncodableWithConfiguration
  • Decodable
  • DecodableWithConfiguration
  • Sendable
  • BitwiseCopyable
  • ~Copyable

Additionally, Delta conforms to RandomAccessCollection, allowing for iteration over the elements and many other operations provided by Sequence, Collection, and BidirectionalCollection.

Using Swift Delta in your project

Add swift-delta as a dependency to your package:

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/Formkunft/swift-delta.git", .upToNextMajor(from: "0.5.1")),
    ],
    targets: [
        .target(
            // ...
            dependencies: [
                .product(name: "DeltaModule", package: "swift-delta"),
            ]),
    ]
)

Then, import DeltaModule in your code:

import DeltaModule

// ...

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed May 14 2025 04:04:40 GMT-0900 (Hawaii-Aleutian Daylight Time)