{"id":24563881,"url":"https://github.com/maartz/swiftpipeline","last_synced_at":"2025-10-10T07:06:25.384Z","repository":{"id":263885904,"uuid":"891399115","full_name":"Maartz/SwiftPipeline","owner":"Maartz","description":"SwiftPipeline is a lightweight, functional-style library for Swift that brings the power of threading macros inspired by languages like Clojure.","archived":false,"fork":false,"pushed_at":"2024-11-21T08:52:53.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T05:22:17.469Z","etag":null,"topics":["functional-programming","swift"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/Maartz/SwiftPipeline","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/Maartz.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}},"created_at":"2024-11-20T09:10:40.000Z","updated_at":"2025-02-13T20:47:28.000Z","dependencies_parsed_at":"2024-11-20T20:35:09.684Z","dependency_job_id":"e3471200-b410-414f-9759-80a66f4ff25e","html_url":"https://github.com/Maartz/SwiftPipeline","commit_stats":null,"previous_names":["maartz/swiftpipeline"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Maartz/SwiftPipeline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maartz%2FSwiftPipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maartz%2FSwiftPipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maartz%2FSwiftPipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maartz%2FSwiftPipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Maartz","download_url":"https://codeload.github.com/Maartz/SwiftPipeline/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maartz%2FSwiftPipeline/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003168,"owners_count":26083533,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["functional-programming","swift"],"created_at":"2025-01-23T10:16:13.390Z","updated_at":"2025-10-10T07:06:25.367Z","avatar_url":"https://github.com/Maartz.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftPipeline\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FMaartz%2FSwiftPipeline%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Maartz/SwiftPipeline)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FMaartz%2FSwiftPipeline%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/Maartz/SwiftPipeline)\n\n[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager)\n\nSwiftPipeline is a lightweight, functional-style library for Swift that brings the power of **threading macros** and **functional operators** inspired by languages like **Clojure** and **Haskell**. With clean and expressive operators, SwiftPipeline allows you to thread data through a series of transformations in a concise and readable way.\n\n## Features 🎯\n\n### Threading Operators\n- **Thread-first (`=\u003e`)**: Passes the value as the first argument to functions or uses KeyPaths for property extraction\n- **Thread-last (`=\u003e\u003e`)**: Passes the value as the last argument to functions\n- **Thread-as (`~=\u003e`)**: Binds a value to a name for custom transformations\n\n### Functional Operators\n- **FlatMap (`\u003c|`)**: Applies functions to optional values or arrays\n- **Applicative (`\u003c*\u003e`)**: Applies wrapped functions to wrapped values\n- **Kleisli composition (`\u003e=\u003e`)**: Composes functions that return optionals\n- **Alternative (`\u003c|\u003e`)**: Provides fallback values for computations\n- **Monadic bind (`\u003e\u003e-`)**: Chains operations that produce optionals\n- **Reverse bind (`-\u003c\u003c`)**: Flipped version of monadic bind\n\n## Why SwiftPipeline? 🤔\n\n### Clean and Declarative Code\n- Transform your Swift code into highly expressive and readable pipelines\n- Chain operations in a natural, left-to-right flow\n- Reduce nested function calls and temporary variables\n- Make complex data transformations clear and maintainable\n\n### Rich Functional Programming Patterns\n- Combines threading macros from **Clojure** with functional operators from **Haskell**\n- Powerful composition with monadic, applicative, and alternative operators\n- Strong type safety while maintaining functional programming elegance\n- Makes optional handling and error propagation elegant\n\n### Lightweight and Swift-Native\n- Zero external dependencies—pure Swift implementation\n- Minimal runtime overhead\n- Small API surface with maximum expressiveness\n- Seamlessly integrates with Swift's type system and standard library\n\n### Flexible and Extensible\n- Works with any Swift type, including your custom types\n- Combines beautifully with Swift's KeyPaths\n- Easy to extend with your own operators\n- Perfect for both small scripts and large applications\n\n### Battle-Tested Patterns\n- Based on proven functional programming concepts\n- Inspired by decades of FP best practices\n- Makes complex operations predictable and safe\n- Reduces cognitive load when dealing with complex transformations\n\n### Great for Teams\n- Makes code intent clear and self-documenting\n- Reduces merge conflicts by encouraging linear transformations\n- Easy to learn, hard to misuse\n- Consistent patterns across your codebase\n\nWhether you're building data pipelines, handling optional chains, or just want cleaner code, SwiftPipeline provides the tools you need without the bloat.\n\n\n## Installation 📥\n\nAdd **SwiftPipeline** to your project using the Swift Package Manager:\n1. Open your project in Xcode\n2. Go to **File \u003e Add Packages**\n3. Enter the following repository URL:\n   ```plaintext\n   https://github.com/Maartz/SwiftPipeline.git\n   ```\n4. Select the latest version and add the package\n\n## Usage 📖\n\n### Basic Threading Operators\n\n#### Thread-first (`=\u003e`)\n```swift\nstruct Person {\n    let name: String\n    let age: Int\n}\n\nlet person = Person(name: \"Alice\", age: 30)\nlet result = person\n    =\u003e \\.name\n    =\u003e { $0.uppercased() }\n// Output: \"ALICE\"\n```\n\n#### Thread-last (`=\u003e\u003e`)\n```swift\nlet numbers = [1, 2, 3]\nlet result = numbers\n    =\u003e\u003e { $0.map { $0 + 1 } }\n    =\u003e\u003e { $0.filter { $0 % 2 != 0 } }\n    =\u003e\u003e { $0.reduce(0, +) }\n// Output: 6\n```\n\n#### Thread-as (`~=\u003e`)\n```swift\nlet total = 5 \n    ~=\u003e { x in x + 10 } \n    =\u003e { $0 * 2 }\n// Output: 30\n```\n\n### Functional Operators\n\n#### Map (`\u003c|`)\n```swift\n// With optionals\nlet double: (Int) -\u003e Int = { $0 * 2 }\nlet result = double \u003c| Some(5)  // Optional(10)\n\n// With arrays\nlet numbers = [1, 2, 3]\nlet doubled = double \u003c| numbers  // [2, 4, 6]\n```\n\n#### Applicative (`\u003c*\u003e`)\n```swift\nlet maybeDouble: ((Int) -\u003e Int)? = { $0 * 2 }\nlet result = maybeDouble \u003c*\u003e Some(5)  // Optional(10)\n\n// With arrays\nlet functions = [{ $0 * 2 }, { $0 + 3 }]\nlet values = [1, 2]\nlet results = functions \u003c*\u003e values  // [2, 4, 4, 5]\n```\n\n#### Alternative (`\u003c|\u003e`)\n```swift\nlet parseNumber: (String) -\u003e Int? = { Int($0) }\nlet result = parseNumber(\"invalid\") \u003c|\u003e parseNumber(\"42\") \u003c|\u003e Some(0)\n// Falls back to valid parsing or default\n```\n\n#### Monadic Bind (`\u003e\u003e-`) and Reverse Bind (`-\u003c\u003c`)\n```swift\nlet parseId: (String) -\u003e Int? = { Int($0) }\nlet findUser: (Int) -\u003e User? = { id in \n    // Find user by id\n    id == 42 ? User(id: 42, name: \"John\") : nil \n}\n\n// Using \u003e\u003e-\nlet user1 = \"42\" \u003e\u003e- parseId \u003e\u003e- findUser\n\n// Using -\u003c\u003c\nlet user2 = findUser -\u003c\u003c (parseId -\u003c\u003c \"42\")\n```\n\n### Complex Examples\n\n#### Optional Chaining with Alternatives\n```swift\nstruct User {\n    let id: Int\n    let email: String?\n}\n\nlet validateEmail: (String) -\u003e String? = { email in\n    email.contains(\"@\") ? email : nil\n}\n\nlet result = parseId -\u003c\u003c \"42\"\n    \u003e\u003e- findUser\n    \u003e\u003e- { user in user.email \u003e\u003e- validateEmail }\n    \u003c|\u003e Some(\"default@email.com\")\n```\n\n#### Applicative with Computations\n```swift\nlet compute: (Int) -\u003e (Int) -\u003e Int? = { x in \n    { y in (x + y) \u003e 0 ? x + y : nil } \n}\n\nlet result = (parseId -\u003c\u003c \"5\" \u003e\u003e- compute) \n    \u003c*\u003e Some(-3) \n    \u003c|\u003e Some(10)\n```\n\n## API Reference 📚\n\n### Operators\n| Operator | Type | Description | Example Usage |\n|----------|------|-------------|---------------|\n| `=\u003e`     | Threading | Thread-first | `value =\u003e function` |\n| `=\u003e\u003e`    | Threading | Thread-last | `value =\u003e\u003e function` |\n| `~=\u003e`    | Threading | Thread-as | `value ~=\u003e { $0 * 2 }` |\n| `\u003c\\|`    | Functional | Map | `function \u003c\\| optional` |\n| `\u003c*\u003e`    | Functional | Applicative | `wrappedFn \u003c*\u003e wrappedValue` |\n| `\u003e=\u003e`    | Functional | Kleisli composition | `f \u003e=\u003e g` |\n| `\u003c\\|\u003e`   | Functional | Alternative | `computation1 \u003c\\|\u003e computation2` |\n| `\u003e\u003e-`    | Functional | Monadic bind | `value \u003e\u003e- function` |\n| `-\u003c\u003c`    | Functional | Reverse bind | `function -\u003c\u003c value` |\n\n## Contributing 🤝\n\nWe welcome contributions! Feel free to:\n- Submit a bug report or feature request\n- Fork the repository and open a pull request\n\n## License 📜\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements 🙏\n\nSwiftPipeline is inspired by the threading macros of **Clojure** and functional operators from **Haskell**, aiming to bring similar functionality to the Swift ecosystem.\n\n---\nEnjoy using SwiftPipeline! 🚀\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaartz%2Fswiftpipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaartz%2Fswiftpipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaartz%2Fswiftpipeline/lists"}