{"id":16335977,"url":"https://github.com/saschagrunert/func","last_synced_at":"2025-03-20T23:30:47.624Z","repository":{"id":78565914,"uuid":"123695712","full_name":"saschagrunert/func","owner":"saschagrunert","description":"Functional additions to C","archived":false,"fork":false,"pushed_at":"2018-03-15T20:11:27.000Z","size":25,"stargazers_count":58,"open_issues_count":0,"forks_count":2,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-17T18:48:35.574Z","etag":null,"topics":["c","cpp","either","functional-programming","maybe"],"latest_commit_sha":null,"homepage":null,"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/saschagrunert.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":"2018-03-03T13:45:35.000Z","updated_at":"2024-12-11T19:37:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2c08875-661e-473c-a619-cf2e756be667","html_url":"https://github.com/saschagrunert/func","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saschagrunert%2Ffunc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saschagrunert%2Ffunc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saschagrunert%2Ffunc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saschagrunert%2Ffunc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saschagrunert","download_url":"https://codeload.github.com/saschagrunert/func/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244710454,"owners_count":20497241,"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":["c","cpp","either","functional-programming","maybe"],"created_at":"2024-10-10T23:42:52.730Z","updated_at":"2025-03-20T23:30:47.619Z","avatar_url":"https://github.com/saschagrunert.png","language":"C++","readme":"# func - Functional additions to C [![Build Status](https://travis-ci.org/saschagrunert/func.svg)](https://travis-ci.org/saschagrunert/func)\n\nFunc provides - header only - functional additions to the C language. For now,\nthe following features are included:\n\n- [`Maybe` data type](./include/Maybe.h)\n- [`Either` data type](./include/Either.h)\n\n## Installation\n\nSimply add the [`include`](./include) folder as a dependency to your project and\ninclude the main header file:\n\n```c\n#include \u003cFunc.h\u003e\n```\n\n## Usage\n\n### Maybe\n\nA Maybe type is a polymorphic type that represents encapsulation of an optional\nvalue.\n\nThe type can be used like this:\n\n```c\n#include \"include/Func.h\"\n\nMAYBE(int, foo);\n\n/* Alternatively, if you dont need the 'foo' synonym:\n * MAYBE_TYPE(int); */\n \n /* Maybe will only take struct pointers */\nstruct bar { int value; };\nMAYBE(struct bar *, bar);\n/* MAYBE(struct bar, bar); */ /* ERROR */\n\nint main(void) {\n    Maybe(foo) maybeFoo = Just_foo(2);\n\n    /* check if the Maybe value contains nothing */\n    if (isNothing(maybeFoo)) {\n        /* wont be executed */\n    }\n\n    /* check if the Maybe value contains something */\n    if (isJust(maybeFoo)) {\n        /* will be executed */\n    }\n\n    /* Extract the content to `t`.\n     * Will evaluate to the default value '0'\n     * if the maybeFoo would be 'Nothing' */\n    int t = fromMaybe(0, maybeFoo);\n\n    /* t will be `2` now */\n\n    return 0;\n}\n```\n\n### Either\n\nThe Either type represents values with two possibilities: a value of type Either\na b is either Left a or Right b.\n\nThe Either type is sometimes used to represent a value which is either correct\nor an error; by convention, the Left constructor is used to hold an error value\nand the Right constructor is used to hold a correct value (mnemonic: \"right\"\nalso means \"correct\").\n\n```c\n#include \"include/Func.h\"\n\nEITHER(int, foo, char, bar);\n\n/* Alternatively, if you dont need the 'foo' and 'bar' synonyms:\n * EITHER_TYPE(int, char); */\n \n /* Either will only take struct pointers */\nstruct baz { int value; };\nEITHER(struct baz *, baz, char, bax);\n/* EITHER(struct baz, baz, char, bax); */ /* ERROR */\n\nint main(void) {\n    Either(foo, bar) eitherFooOrBar = Right_foo_bar('a');\n\n    if (isLeft(eitherFooOrBar)) {\n        /* wont be executed */\n    }\n\n    if (isRight(eitherFooOrBar)) {\n        /* will be executed */\n    }\n\n    /* Try to extract the Left content to `x`.\n     * Will evaluate to the default '1' if the\n     * Either type would be 'Right' */\n    int x = fromLeft(1, eitherFooOrBar);\n\n    /* x will be '1' */\n\n    /* Try to extract the Right content to `y`.\n     * Will evaluate to the default ' ' if the\n     * Either type is 'Left' */\n    char y = fromRight(' ', eitherFooOrBar);\n\n    /* y will be 'a' */\n\n    return 0;\n}\n```\n\n## Contributing\nYou want to contribute to this project? Wow, thanks! So please just fork it and\nsend me a pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaschagrunert%2Ffunc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaschagrunert%2Ffunc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaschagrunert%2Ffunc/lists"}