{"id":21072339,"url":"https://github.com/g0mb4/funcpp","last_synced_at":"2025-06-26T12:35:03.394Z","repository":{"id":148469536,"uuid":"370489877","full_name":"g0mb4/funcpp","owner":"g0mb4","description":"Functional C++, it's fun.","archived":false,"fork":false,"pushed_at":"2021-06-15T11:18:47.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T03:11:10.338Z","etag":null,"topics":["functional-programming","header-only"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/g0mb4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-05-24T21:32:38.000Z","updated_at":"2021-06-15T11:18:49.000Z","dependencies_parsed_at":"2023-05-20T06:45:36.738Z","dependency_job_id":null,"html_url":"https://github.com/g0mb4/funcpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/g0mb4/funcpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g0mb4%2Ffuncpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g0mb4%2Ffuncpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g0mb4%2Ffuncpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g0mb4%2Ffuncpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/g0mb4","download_url":"https://codeload.github.com/g0mb4/funcpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g0mb4%2Ffuncpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262068698,"owners_count":23253852,"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","header-only"],"created_at":"2024-11-19T18:56:11.556Z","updated_at":"2025-06-26T12:35:03.352Z","avatar_url":"https://github.com/g0mb4.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# funcpp\n\nFunctional C++, it's fun.\n\nThis experiment shows how to use C++ as a functional language. Loops (**for**, **while**) and jumps (**goto**) are not allowed.\n\n# Types\n\nThe fundamental type is **Var** (*v*). It is internally either a numberic value (**Number**, *n*) or a list (**List**, *l*).\n\n## Creation\n\n```c++\nVar n = Number::number(2);  // = 2.\nVar l1 = List::list(std::vector\u003cint\u003e({1, 2, 3})); // = [1, 2, 3]\nVar l2 = List::list(1, 3);  // = [1, 2, 3]\nVar l3 = List::empty();     // = []\n```\n\n## Helpers\n\n```c++\nint i = as_int(v);     // interprets v as an int\n// For internal use only:\nauto l = as_list(v);    // interprets v as a list\nauto n = as_number(v);  // interprets v as a number\n```\n\n# Functions\n\nThe functions operate on the **Var** types. The correctness of the types is checked during run-time.\n\nGeneric functions:\n\n+ ```print(v)``` - prints the string representation of ```v``` to the sandard output\n\nList operations:\n\n+ ```length(l)``` - a number with the value of the number of elements of ```l```\n+ ```head(l)``` -  the first element of ```l```\n+ ```tail(l)``` - a list containing the elements of ```l``` excluding the first element\n+ ```append(n, l)``` - a list created by appending ```n``` to the end of ```l```\n+ ```concat(l1, l2)``` - a list containing the elements of ```l1``` and ```l2```\n\nArithmetic operation:\n\n+ ```add(n1, n2)``` - a number with the value of ```n1``` + ```n2```\n+ ```sub(n1, n2)``` - a number with the value of ```n1``` - ```n2```\n+ ```mult(n1, n2)``` - a number with the value of ```n1``` * ```n2```\n+ ```idiv(n1, n2)``` - a number with the value of ```n1``` / ```n2```, where '/' is the integer division\n\nHigher-order functions:\n\n+ ```map(f(n), l)``` - a list created by applying ```f``` to every element of ```l```\n+ ```filter(f(n), l)``` - a list from ```l``` where ```f``` is true for every element of this list \n\n# Examples\n\nDemo:\n\n```c++\n#include \u003cfuncpp.h\u003e\n\nVar add2(Var \u0026 value){\n    return add(value, Number::number(2));\n}\n\nbool odd(Var \u0026 value){\n    return as_int(value) % 2 != 0;\n}\n\nint main() {\n    auto l = List::list(std::vector\u003cint\u003e({1, 2, 3}));\n\n    print(l);\n    print(head(l));\n    print(tail(l));\n    print(concat(List::list(head(l)), tail(l)));\n    print(map(add2, l));\n    print(filter(odd, l));\n\n    return 0;\n}\n```\n\nFiltering out prime numbers:\n\n```c++\n#include \u003cfuncpp.h\u003e\n\nbool is_prime(int n, int i = 2){\n    if(n \u003c= 1){\n        return false;\n    } else if(n == 2){\n        return true;\n    } else if(i * i \u003e n){\n        return true;\n    } else if(n % i == 0){\n        return false;\n    } else {\n        return is_prime(n, i + 1);\n    }\n}\n\nbool prime(Var \u0026 value){\n    return is_prime(as_int(value));\n}\n\nint main(){\n    Var l = List::list(1, 100);\n\n    print(l);\n    print(filter(prime, l));\n\n    return 0;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg0mb4%2Ffuncpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg0mb4%2Ffuncpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg0mb4%2Ffuncpp/lists"}