Skip to content

Repository files navigation

GitHub License GitHub Tag CI Swift Package Manager Compatible Written in Swift Apple platforms Linux

XCEPipeline

XCEPipeline adds small, typed-throws-aware building blocks for readable value chains in Swift 6. Use operators for compact pipelines, take(_:) and SimpleWrapper for method-style chains, or the Optional helpers when a value may be absent.

See the changelog for breaking changes and migration guidance.

import XCEPipeline

let message = 22
    ./ String.init
    ./ { "Value: \($0)" }

message .* { print($0) }

Custom Operators

Operator Description
./ Pass through — transform value and continue the chain
.? Pass through unwrapped — unwrap optional, then transform
.+ Mutate — modify value in place via inout
.- Inspect — observe value without modifying it
.* End chain — transform and return final result
.?* End chain unwrapped — unwrap optional, transform, and return
.! Ensure condition — assert a condition or throw
?! Unwrap or throw — unwrap optional or throw an error

Operators associate from left to right, so each result becomes the next operation's input. Throwing closures preserve their concrete error type.

enum ValidationError: Error { case missingName }

let name: String? = "Taylor"
let normalized = try name
    ?! ValidationError.missingName
    ./ { $0.trimmingCharacters(in: .whitespaces) }
    .! { !$0.isEmpty }

Async/Await Support

Transformation, mutation, inspection, condition, and terminal operators have async variants, making them compatible with actors and structured concurrency.

SimpleWrapper & take()

Use take(_:) as the public entry point to wrap a nonoptional value in a SimpleWrapper. Its initializer is intentionally not public. Read .value to finish the chain.

  • map — transform the wrapped value (sync + async)
  • inspect — observe the value without changing it (sync + async)
  • mutate — modify the value in place (sync + async)
let result = try take([1, 2])
    .mutate { $0.append(3) }
    .inspect { print($0) }
    .map { $0.reduce(0, +) }
    .value

For optionals, take(optionalValue) returns the optional unchanged so you can continue with standard map plus inspect(_:), mutate(_:), and filter(_:).

Error Types

The .! operator throws ConditionCheckError<PredicateError>:

  • .conditionCheckFailed means the predicate returned false.
  • .predicateBodyError(error) preserves an error thrown by the predicate.

The ?! operator throws the caller-supplied error directly. Errors from transformation, inspection, mutation, and terminal closures also retain their concrete type through Swift 6 typed throws.

How to install

XCEPipeline 4 requires Swift 6 or newer. It supports macOS 12, iOS 15, Mac Catalyst 15, tvOS 15, watchOS 8, and visionOS 1 or newer. The platform-independent API is also supported on Linux with Swift 6.

Install using SwiftPM.

.package(url: "https://github.com/XCEssentials/XCEPipeline.git", from: "4.0.0")

Migrating from 3.x

Version 4 compiles in Swift 6 language mode and therefore requires a Swift 6 toolchain. The pipeline operators and their behavior are unchanged.

About

Custom pipeline operators for easy chaining in Swift.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Used by

Contributors

Languages