{"id":41575119,"url":"https://github.com/capturecontext/swift-equated","last_synced_at":"2026-02-03T14:06:40.434Z","repository":{"id":331973266,"uuid":"1130994983","full_name":"CaptureContext/swift-equated","owner":"CaptureContext","description":"Equatable wrapper type and a set of basic comparators","archived":false,"fork":false,"pushed_at":"2026-01-09T10:12:24.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-24T17:21:15.463Z","etag":null,"topics":["equatable","foundation","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CaptureContext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-09T10:11:49.000Z","updated_at":"2026-01-09T10:13:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/CaptureContext/swift-equated","commit_stats":null,"previous_names":["capturecontext/swift-equated"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/CaptureContext/swift-equated","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-equated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-equated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-equated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-equated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptureContext","download_url":"https://codeload.github.com/CaptureContext/swift-equated/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-equated/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29047204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["equatable","foundation","swift"],"created_at":"2026-01-24T08:14:11.467Z","updated_at":"2026-02-03T14:06:38.671Z","avatar_url":"https://github.com/CaptureContext.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-equated\n\n[![CI](https://github.com/CaptureContext/swift-equated/actions/workflows/ci.yml/badge.svg)](https://github.com/CaptureContext/swift-equated/actions/workflows/ci.yml) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FCaptureContext%2Fswift-equated%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/CaptureContext/swift-equated) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FCaptureContext%2Fswift-equated%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/CaptureContext/swift-equated)\n\nEquatable wrapper type and a set of basic comparators.\n\n## Table of Contents\n\n  - [Motivation](#motivation)\n  - [The problem](#the-problem)\n  - [The solution](#the-solution)\n  - [Features](#features)\n    - [Predefined comparators](#predefined-comparators)\n\n  - [Installation](#installation)\n    - [Basic](#basic)\n    - [Recommended](#recommended)\n\n  - [License](#license)\n\n## Motivation\n\nSwift strongly encourages `Equatable`, and for good reason.  \nBut in practice, equality often disappears at API boundaries:\n\n- values stored as `any`\n- errors erased to `Swift.Error`\n- closures, reference types, or foreign types\n- generic code that cannot add `Equatable` constraints\n\n## The problem\n\nA very common example of this appears when using [TCA](https://github.com/pointfreeco/swift-composable-architecture), though the issue is by no means specific to it.\n\nIn TCA it’s idiomatic to make `Action`s equatable for better testing, diffing,\nand debugging. But the moment you want to carry an error, you hit a wall:\n\n```swift\nenum Action: Equatable {\n  case requestFailed(Error) // ❌ 'Error' does not conform to 'Equatable'\n}\n```\n\nA typical workaround is to introduce a bespoke wrapper type that *forces*\nequatability by comparing something like `localizedDescription`:\n\n```swift\nstruct EquatableError: LocalizedError, Equatable {\n  static func == (lhs: Self, rhs: Self) -\u003e Bool {\n    lhs.localizedDescription == rhs.localizedDescription\n  }\n\n  let underlyingError: Error\n\n  var localizedDescription: String {\n    underlyingError.localizedDescription\n  }\n}\n\nenum FeatureAction: Equatable {\n  case requestFailed(EquatableError) // ✅ compiles\n}\n```\n\nThis works, but it comes with tradeoffs:\n\n- a new wrapper type must be declared\n- an equality strategy must be chosen and documented\n- the same pattern is often repeated across features and modules\n\nAnd the “right” definition of equality is frequently context-dependent.\n\n## The solution\n\n`Equated` lets you keep actions equatable **without** defining custom wrapper types:\n\n```swift\nimport Equated\n\nenum FeatureAction: Equatable {\n  case requestFailed(Equated\u003cError\u003e) // ✅ compiles\n}\n```\n\nFor errors, it’s enough to simply wrap the value:\n\n```swift\nreturn .send(.requestFailed(Equated(error)))\n```\n\nBy default, `Equated` chooses an appropriate equality strategy:\n\n- if the underlying error can be compared using `Equatable`, `==` is used\n- otherwise it falls back to comparing `localizedDescription`\n\n\u003e [!NOTE]\n\u003e _Comparing `localizedDescription` is a heuristic. It is common, but not guaranteed to be unique or stable across localization changes._\n\nEquality can always be customized explicitly when needed:\n\n```swift\nreturn .send(.requestFailed(Equated(error, by: .property(\\.code))))\n```\n\n## Features\n\n`Equated` is a lightweight `Equatable` container that lets you define equality explicitly, while keeping call sites terse.\n\n### Predefined comparators\n\nChoose how two values should be compared using a `Equated.Comparator`:\n\n#### Automatic\n\nThe `detectEquatable` comparator attempts to cast values to `any Equatable` and compare them using `==`:\n\n```swift\n.detectEquatable(\n  checkBoth: Bool = false,\n  fallback: Comparator = .dump\n)\n```\n\nIf equatable comparison is not possible, the provided `fallback` comparator is used.\n\n#### Building blocks\n\n- `.const(Bool)` – always equal / never equal\n- `.custom((Value, Value) -\u003e Bool)` – full control\n- `.dump` – compares the textual `dump()` output\n\n#### Equatable-driven\n\n- `.defaultEquatable` – equivalent to using `==` directly\n\n#### Property-based\n\nThe `property` comparator compares values by a derived equatable projection:\n\n```swift\n.property(\\.someEquatableProperty)\n.property { String(reflecting: $0) }\n```\n\n- `.objectID` – compare reference identity (only when `Value: AnyObject`)\n\n#### Error convenience\n\nThe `.localizedDescription` comparator is equivalent to `.property(\\.localizedDescription)`.\n\nIt is typically most useful as a fallback, for example:\n\n```swift\n.detectEquatable(fallback: .localizedDescription)\n```\n\n#### Concurrency escape hatches\n\n- `.uncheckedSendable((Value) -\u003e any Equatable)`\n\n  _A `property`-style comparator for non-sendable projections_\n- `.uncheckedSendable((Value, Value) -\u003e Bool)`\n\n  _A `custom`-style comparator for non-sendable values_\n\n\u003e [!NOTE]\n\u003e\n\u003e _Most users should prefer `.detectEquatable()` or `.property`_ comparators\n\n## Installation\n\n### Basic\n\nYou can add Equated to an Xcode project by adding it as a package dependency.\n\n1. From the **File** menu, select **Swift Packages › Add Package Dependency…**\n2. Enter [`\"https://github.com/capturecontext/swift-equated\"`](https://github.com/capturecontext/swift-equated) into the package repository URL text field\n3. Choose products you need to link them to your project.\n\n### Recommended\n\nIf you use SwiftPM for your project structure, add Equated to your package file.\n\n```swift\n.package(\n  url: \"https://github.com/capturecontext/swift-equated.git\",\n  .upToNextMinor(from: \"0.0.1\")\n)\n```\n\nor via HTTPS\n\n```swift\n.package(\n  url: \"https://github.com/capturecontext/swift-equated.git\",\n  .upToNextMinor(\"0.0.1\")\n)\n```\n\nDo not forget about target dependencies:\n\n```swift\n.product(\n  name: \"Equated\",\n  package: \"swift-equated\"\n)\n```\n\n## License\n\nThis library is released under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-equated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapturecontext%2Fswift-equated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-equated/lists"}