{"id":25816395,"url":"https://github.com/mnikander/cpp_sequence","last_synced_at":"2025-10-19T08:33:39.048Z","repository":{"id":278145924,"uuid":"873172815","full_name":"mnikander/cpp_sequence","owner":"mnikander","description":"Sequence pipelines in C++. A functional programming-inspired approach to processing data with map, filter, reduce, and more.","archived":false,"fork":false,"pushed_at":"2025-02-25T11:51:38.000Z","size":147,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-25T12:34:16.932Z","etag":null,"topics":["algorithm","cpp","cpp17","functional-programming","generator","map-filter-reduce","pipeline","rappel","sequence"],"latest_commit_sha":null,"homepage":"","language":"C++","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/mnikander.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}},"created_at":"2024-10-15T18:08:14.000Z","updated_at":"2025-02-25T11:51:41.000Z","dependencies_parsed_at":"2025-02-25T12:26:19.651Z","dependency_job_id":null,"html_url":"https://github.com/mnikander/cpp_sequence","commit_stats":null,"previous_names":["mnikander/cpp_sequence"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_sequence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_sequence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_sequence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_sequence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnikander","download_url":"https://codeload.github.com/mnikander/cpp_sequence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241104812,"owners_count":19910506,"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":["algorithm","cpp","cpp17","functional-programming","generator","map-filter-reduce","pipeline","rappel","sequence"],"created_at":"2025-02-28T05:21:17.520Z","updated_at":"2025-10-19T08:33:39.043Z","avatar_url":"https://github.com/mnikander.png","language":"C++","readme":"\n# Sequence Library\n\n**Composable and easy-to-use pipelines for sequence processing in C++.**\n\nThis library provides a lightweight and expressive way to process sequences of values using functional programming concepts.\nInspired by Kotlin Sequences and the C++ [Rappel](https://www.youtube.com/watch?v=itnyR9j8y6E) library, it enables the creation of **clear and easily composable data transformations**.\n\n## Features\n\n- **Composable Functional Pipelines** – Chain `map`, `filter`, `reduce`, and more\n- **Readable Compile-Time Errors** – Short, clear error messages for easier debugging\n- **Avoids Iterator Pitfalls** – Uses generators instead of iterators to sidestep C++ iterator complexities\n\n## Quick Example\n\nBefore diving into details, here’s a simple example demonstrating how to create and run a sequence pipeline:\n\n```cpp\n#include \"src/sequence.hpp\"\nusing namespace seq;\n\nstd::vector\u003cint\u003e result;\n\nauto pipeline = from_iota(\n    map\u003cint\u003e([](int x) { return x * x; },\n        take\u003cint\u003e(3,\n            to_vector(result))));\n\npipeline.run(); // Generates {0, 1, 4}\n```\n\nThis pipeline:\n\n1. Generates integers from `0` onwards (`from_iota`)\n2. Squares each value (`map`)\n3. Takes the first 3 values (`take`)\n4. Collects them in `result` (`to_vector`)\n\n---\n\n## Installation \u0026 Setup\n\n### **1. Install Dependencies**\n\n```bash\nsudo apt install g++ cmake libgtest-dev libbenchmark-dev\n```\n\n### **2. Clone the Repository**\n\n```bash\ngit clone git@github.com:mnikander/cpp_sequence.git\ncd cpp_sequence\n```\n\n### **3. Build and Run Tests**\n\n```bash\nmkdir out \u0026\u0026 cd out \u0026\u0026 cmake .. \u0026\u0026 cd ..\ncmake --build out/ \u0026\u0026 ./out/unit_tests\n```\n\n---\n\n## How It Works\n\nThis library models a **pipeline** using three building blocks:\n\n- **Source** – Generates values (`from_iota`, `from_vector`, etc.)\n- **Stage** – Transforms values (`map`, `filter`, `take`, `reduce`, etc.)\n- **Sink** – Collects results (`to_vector`, `to_value`, etc.)\n\nA sequence processes values individually, pushing them through the stages step by step.\n\n### Example: **Map-Filter-Reduce Pipeline**\n\n```cpp\n#include \"src/sequence.hpp\"\nusing namespace seq;\n\nint result = 0;\n\nauto pipeline = from_iota(\n    map\u003cint\u003e([](int i) { return i - 3; },\n        filter\u003cint\u003e([](int i) { return i % 2 == 0; },\n            reduce\u003cint\u003e(std::plus\u003cint\u003e{}, 0,\n                to_value(result)))));\n\npipeline.yield(8); // Process first 8 elements, filtering evens\nassert(result == 4); // Sum of (-2, 0, 2, 4)\n```\nEach stage in the pipeline _must_ explicitly specify its input type (e.g., `map\u003cint\u003e`, `filter\u003cint\u003e`).\nThis ensures simple compile-time type checking and results in clear, readable error messages, preventing template-related confusion.\nMany more usage examples can be found in the [unit tests](https://github.com/mnikander/cpp_sequence/tree/main/test)!\n\u003e Note: forgetting to specify the input type of stage is a common cause of errors such as _\"no instance of function template 'reduce' matches the argument list\"_.\n\n### **Is it fast?**\n\nA [simple benchmark](https://github.com/mnikander/cpp_sequence/blob/main/benchmark/reduce.benchmark.cpp) is included, which generates a random vector of integers and sums all the even integers together.\nInitial benchmarking runs indicate that the sequence implementation takes 2-6 times as long as a handcrafted for-loop.\n\n### **Why Not Just Use `std::ranges`?**\n\nWhile `std::ranges` provides powerful sequence transformations, this library offers:\n\n- **Generator-based execution** – Avoids [complex iterator issues](https://www.fluentcpp.com/2019/02/12/the-terrible-problem-of-incrementing-a-smart-iterator/)\n- **More readable error messages** – Explicit input types prevent cryptic template errors\n- **Minimal boilerplate** – Easily chainable and more intuitive syntax\n\nIf you’re looking for a **simple alternative to iterators** with **clear syntax and minimal boilerplate**, this library is a good fit!\n\n---\n\n**Copyright (c) 2024, Marco Nikander**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnikander%2Fcpp_sequence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnikander%2Fcpp_sequence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnikander%2Fcpp_sequence/lists"}