{"id":25195046,"url":"https://github.com/rvarago/funktions","last_synced_at":"2025-04-04T15:12:30.786Z","repository":{"id":56175315,"uuid":"278109629","full_name":"rvarago/funktions","owner":"rvarago","description":"A small C++17 set of utilities for functional composition.","archived":false,"fork":false,"pushed_at":"2020-11-22T18:46:32.000Z","size":80,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T00:41:21.566Z","etag":null,"topics":["cplusplus","cplusplus-17","cpp","cpp17","dsl","functional-programming"],"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/rvarago.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}},"created_at":"2020-07-08T14:20:52.000Z","updated_at":"2021-05-28T17:57:36.000Z","dependencies_parsed_at":"2022-08-15T14:10:09.470Z","dependency_job_id":null,"html_url":"https://github.com/rvarago/funktions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Ffunktions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Ffunktions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Ffunktions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Ffunktions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvarago","download_url":"https://codeload.github.com/rvarago/funktions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198469,"owners_count":20900081,"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":["cplusplus","cplusplus-17","cpp","cpp17","dsl","functional-programming"],"created_at":"2025-02-10T00:41:01.350Z","updated_at":"2025-04-04T15:12:30.757Z","avatar_url":"https://github.com/rvarago.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# funktions\n\nA small C++17 set of utilities for functional composition.\n\n```Cpp\nenum class status { Idle, Waiting, Busy };\n\nstruct device {\n    long id;\n    long vendor_id;\n    status current_status;\n};\n\nstd::vector\u003cdevice\u003e const devices = fetch_all_devices();\n\n// Given a device d:\n//  d.vendor_id == 2 and d.current_status != status::Busy\nauto const query = fn(\u0026device::vendor_id) \u003e\u003e eq(2)\n                    \u0026 fn(\u0026device::current_status) \u003e\u003e ne(status::Busy);\n\n// 'fn', 'eq', 'ne', '\u003e\u003e', and '\u0026' are some of the utilities provided by\n// funktions to build fluent Domain-Specific Languages.\n\nauto const device = std::find_if(devices.begin(), devices.end(), query);\n```\n\n# Utilities\n\n* [`fn_wrapper`](#fn_wrapper)\n* [`logical_not`](#logical_not)\n* [`logical_and`](#logical_and)\n* [`logical_or`](#logical_or)\n* [`chain`](#chain)\n* [`predicates`](#predicates)\n\n[funktions/all.h](include/funktions/all.h)\n\n## \u003cA name=\"fn_wrapper\"/\u003e`fn_wrapper`\n\nA wrapper around a generic function-like type to make DSLs created via operator-overloading less intrusive.\n\nWhen invoked with a pack of arguments forwards them to the wrapped callable.\n\n[funktions/fnwrapper.h](include/funktions/fnwrapper.h)\n\n## \u003cA name=\"logical_not\"/\u003e`logical_not`\n\nAn overload for the `operator!` that acts on a predicate wrapped in `fn_wrapper` to produce another predicate.\n\nWhen invoked with a pack of arguments, forwards them to the predicate and computes the logical-not of its outcome.\n\n*Example*:\n\n```Cpp\nauto const eq_2 = [](auto const x) { return x == 2; };\n\nauto const not_eq_2 = !fn(eq_2);\n\nauto const y = not_eq_2(x); // y = !(x == 2)\n```\n\n[funktions/logical.h](include/funktions/logical.h)\n\n## \u003cA name=\"logical_and\"/\u003e`logical_and`\n\nAn overload for the `operator\u0026` that acts on two predicates wrapped in `fn_wrapper`s to produce a third predicate.\n\nWhen invoked with a pack of arguments, forwards them to each predicate and computes the logical-and of their outcomes.\n\n*Example*:\n\n```Cpp\nauto const gt_2 = [](auto const x) { return x \u003e 2; };\nauto const lt_6 = [](auto const x) { return x \u003c 6; };\n\nauto const bt_2_6 = fn(gt_2) \u0026 fn(lt_6);\n\nauto const y = bt_2_6(x); // y = (x \u003e 2) \u0026\u0026 (x \u003c 6)\n```\n\n[funktions/logical.h](include/funktions/logical.h)\n\n## \u003cA name=\"logical_or\"/\u003e`logical_or`\n\nAn overload for the `operator|` that acts on two predicates wrapped in `fn_wrapper`s to produce a third predicate.\n\nWhen invoked with a pack of arguments, forwards them to each predicate and computes the logical-or of their outcomes.\n\n*Example*:\n\n```Cpp\nauto const eq_2 = [](auto const x) { return x == 2; };\nauto const eq_6 = [](auto const x) { return x == 6; };\n\nauto const eq_2_or_6 = fn(eq_2) | fn(eq_6);\n\nauto const y = eq_2_or_6(x); // y = (x == 2) || (x == 6)\n```\n\n[funktions/logical.h](include/funktions/logical.h)\n\n## \u003cA name=\"chain\"/\u003e`chain`\n\nAn overload for the `operator\u003e\u003e` that acts on two functions wrapped in `fn_wrapper` to produce a third function (their composition).\n\nWhen invoked with a pack of arguments, forwards them to the first function and then applies its\noutcome into the second function.\n\n*Example*:\n\n```Cpp\nauto const plus_1 = [](auto const x) { return x + 1; };\nauto const square = [](auto const x) { return x * x; };\n\nauto const plus_1_then_square = fn(plus_1) \u003e\u003e square;\n\nauto const y = plus_1_then_square(x); // y = (x + 1) * (x + 1)\n```\n\n[funktions/chain.h](include/funktions/chain.h)\n\n\n## \u003cA name=\"predicates\"/\u003e`predicates`\n\nA set of reusable and curried predicates for common operations that would otherwise likely be written as inline lambdas.\n\nThese operations are already wrapped inside `fn_wrapper`s to profit from logical combinators.\n\nBuilt-in operations:\n\n* `eq(x)(y)         // y == x`\n* `ne(x)(y)         // y != x`\n* `lt(x)(y)         // y \u003c x`\n* `gt(x)(y)         // y \u003e x`\n* `is_true()(y)     // y == true`\n* `is_false()(y)    // y == false`\n\n[funktions/predicates.h](include/funktions/predicates.h)\n\n# Examples\n\n[device_validation.cpp](examples/device_validation.cpp)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvarago%2Ffunktions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvarago%2Ffunktions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvarago%2Ffunktions/lists"}