{"id":18818054,"url":"https://github.com/pointfreeco/swift-prelude","last_synced_at":"2025-04-04T09:08:53.571Z","repository":{"id":37493438,"uuid":"94474283","full_name":"pointfreeco/swift-prelude","owner":"pointfreeco","description":"🎶 A collection of types and functions that enhance the Swift language.","archived":false,"fork":false,"pushed_at":"2024-07-04T01:04:57.000Z","size":277,"stargazers_count":472,"open_issues_count":0,"forks_count":53,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-03-28T08:06:16.771Z","etag":null,"topics":["functional-programming","prelude","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":false,"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/pointfreeco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2017-06-15T19:59:50.000Z","updated_at":"2025-01-29T01:22:31.000Z","dependencies_parsed_at":"2024-11-15T01:00:56.802Z","dependency_job_id":"c9677f92-5725-4d79-88d8-c5180fd215ca","html_url":"https://github.com/pointfreeco/swift-prelude","commit_stats":{"total_commits":148,"total_committers":11,"mean_commits":"13.454545454545455","dds":0.4797297297297297,"last_synced_commit":"f2bac333653b36e0c2cccaa345f3e174e08dcd8b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-prelude","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-prelude/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-prelude/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-prelude/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pointfreeco","download_url":"https://codeload.github.com/pointfreeco/swift-prelude/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["functional-programming","prelude","swift"],"created_at":"2024-11-08T00:14:43.482Z","updated_at":"2025-04-04T09:08:53.553Z","avatar_url":"https://github.com/pointfreeco.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# swift-prelude\n\n[![Swift 5.1](https://img.shields.io/badge/swift-5.1-ED523F.svg?style=flat)](https://swift.org/download/)\n[![CI](https://github.com/pointfreeco/swift-prelude/workflows/CI/badge.svg)](https://actions-badge.atrox.dev/pointfreeco/swift-prelude/goto)\n[![@pointfreeco](https://img.shields.io/badge/contact-@pointfreeco-5AA9E7.svg?style=flat)](https://twitter.com/pointfreeco)\n\nA collection of frameworks to enhance the Swift language.\n\n## Stability\n\nThis library should be considered experimental. If you find its contents useful, please consider maintaining a fork.\n\n## Installation\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  dependencies: [\n    .package(url: \"https://github.com/pointfreeco/swift-prelude.git\", .branch(\"main\")),\n  ]\n)\n```\n\n## Table of Contents\n\n* [`Prelude`](#prelude)\n* [`Either`](#either)\n* [`Optics`](#optics)\n* [`ValidationSemigroup`](#validationsemigroup)\n* [`ValidationNearSemiring`](#validationnearsemiring)\n\n## `Prelude`\n\nA collection of types and functions to build powerful abstractions and enhance the Swift standard library.\n\n## `Either`\n\nA type to express a value that holds one of two other types.\n\n```swift\nimport Either\n\nlet intOrString = Either\u003cInt, String\u003e.left(2)\n\nintOrString\n  .bimap({ $0 + 1 }, { $0 + \"!\" }) // =\u003e .left(3)\n```\n\n## `Optics`\n\nA `Lens` type and a bridge between the lens world and the Swift key path world.\n\n```swift\nimport Optics\nimport Prelude\n\nstruct User {\n  var id: Int\n  var name: String\n}\n\nlet uppercased: (String) -\u003e String = { $0.uppercased() }\n\nlet user = User(id: 1, name: \"Blob\")\n\nuser\n  |\u003e \\.id .~ 2\n  |\u003e \\.name %~ uppercased\n\n// =\u003e User(2, \"BLOB\")\n```\n\n## `ValidationSemigroup`\n\nThe `Validation\u003cE, A\u003e` type is a type similar to `Result\u003cE, A\u003e`, except it is given a different applicative instance in the case that `E` is a semigroup. This allows you to accumulate multiple errors into `E` instead of just taking the first error:\n\n```swift\nimport Prelude\nimport ValidationSemigroup\n\nstruct User { let name: String; let bio: String; let email: String }\nlet createUser = { name in { bio in { email in User(name: name, bio: bio, email: email) } } }\n\nfunc validate(name: String) -\u003e Validation\u003c[String], String\u003e {\n  return !name.isEmpty\n    ? pure(name)\n    : .invalid([\"Name must be at least 1 character.\"])\n}\n\nfunc validate(bio: String) -\u003e Validation\u003c[String], String\u003e {\n  return bio.count \u003c= 10\n    ? pure(bio)\n    : .invalid([\"Bio must 10 characters or less.\"])\n}\n\nfunc validate(email: String) -\u003e Validation\u003c[String], String\u003e {\n  return email.contains(\"@\")\n    ? pure(email)\n    : .invalid([\"Email must be valid.\"])\n}\n\nlet validUser = pure(createUser)\n  \u003c*\u003e validate(name: \"Blob\")\n  \u003c*\u003e validate(bio: \"I'm a blob\")\n  \u003c*\u003e validate(email: \"blob@pointfree.co\")\n// =\u003e .valid(User(name: \"Blob\", bio: \"I'm a blob\", email: \"blob@pointfree.co\"))\n\nlet invalidUser = pure(createUser)\n  \u003c*\u003e validate(name: \"Blob\")\n  \u003c*\u003e validate(bio: \"Blobbin around the world\")\n  \u003c*\u003e validate(email: \"blob\")\n// =\u003e .invalid([\"Bio must 10 characters or less.\", \"Email must be valid.\"])\n```\n\nFor more information, watch [Stephen Celis’](http://www.twitter.com/stephencelis) [talk](https://www.youtube.com/watch?v=Awva79gjoHY).\n\n## `ValidationNearSemiring`\n\nThis `Validation\u003cE, A\u003e` type is a type similar to `Result\u003cE, A\u003e` and the above `Validation`, except it is given a different applicative instance in the case that `E` is a `NearSemiring`. This allows you to accumulate errors that describe conditions that hold with both “and” and “or”, e.g. name is required _and_ either email _or_ phone is required.\n\n## License\n\nAll modules are released under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fswift-prelude","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpointfreeco%2Fswift-prelude","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fswift-prelude/lists"}