{"id":18376317,"url":"https://github.com/fmind/gampy","last_synced_at":"2025-04-11T04:43:15.577Z","repository":{"id":57433016,"uuid":"175447839","full_name":"fmind/gampy","owner":"fmind","description":" General Abstract Meta Programming for Python","archived":false,"fork":false,"pushed_at":"2019-07-04T08:59:56.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T04:43:12.774Z","etag":null,"topics":["abstract","algebra","metaprogramming","program","python"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fmind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-13T15:24:26.000Z","updated_at":"2019-07-04T08:59:58.000Z","dependencies_parsed_at":"2022-08-27T20:52:16.424Z","dependency_job_id":null,"html_url":"https://github.com/fmind/gampy","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/fmind%2Fgampy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmind%2Fgampy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmind%2Fgampy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmind%2Fgampy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fmind","download_url":"https://codeload.github.com/fmind/gampy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345281,"owners_count":21088242,"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":["abstract","algebra","metaprogramming","program","python"],"created_at":"2024-11-06T00:22:51.533Z","updated_at":"2025-04-11T04:43:15.558Z","avatar_url":"https://github.com/fmind.png","language":"HTML","readme":"# Gampy\n\nGampy provides experimental constructs to improve your Python programs.\n\n## Pipeline\n\nWhile functional programming is a great paradigm to create data pipelines, some operations remains hard to express:\n- wrap every function of a data pipeline with an external function (e.g. logging, safe exception handling ...)\n- concatenate and transform data pipelines with algebra operators (e.g. convert and compare a pipeline ...)\n- apply the `compose` and `partial` operators on a data pipeline to create a single callable function\n\nGampy Pipeline is a data structure created to address these problems.\n\nHere is an example of a simple pipeline:\n\n```python\nfrom gampy.structures import Pipeline\n\npipeline = Pipeline([\n    (map, [lambda x: x + 1], {}),\n    (filter, [lambda x: x % 2 == 0]),\n    (list,)\n])\n```\n\nEach **step** of the pipeline is represented as a 3-tuple: `(function, arguments, keyword arguments)`. While `function` is mandatory, `arguments` and `keyword argument` will be replaced by `list()` and `dict()` respectively if they are missing. This structure allows the creation of **unevaluated expression**, that can be further transformed prior to their execution.\n\nThe most interesting operations over a pipeline are `()` (call) and `@` (matmul).\n\n`Call` converts the pipeline into a single function. This process is divided in two steps:\n- `functools.partial` is applied on each step arguments to create a single function per step\n- functions are composed two by two with `functools.reduce` to create a single function per pipeline\n\n```python\n\u003e\u003e\u003e f = pipeline()\n\u003e\u003e\u003e f(range(10))\n30\n```\n\n`Matmul` applies **an advice** to each function of the pipeline. This allows the expression of cross concern aspects.\n\nIn the snippet below, any exception raised by a pipeline function will return `None`.\n\n```python\nfrom gampy.advices import exceptional\n\nsafepipe = pipeline @ exceptional(None)\n```\n\nAn advice is similar to a **parametrized decorator**, which create a function that takes a function and replaced it by a new function. The purpose is to extend the behavior of the original function.\n\n```python\ndef exceptional(x: Any = None, on: Type[Exception] = Exception) -\u003e Advice:\n    \"\"\"Return x when f raises an exception.\"\"\"\n\n    def advice(f):\n        @wraps(f)\n        def wrapped(*args, **kwargs):\n            try:\n                return f(*args, **kwargs)\n            except on:\n                return x\n\n        return wrapped\n\n    return advice\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmind%2Fgampy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffmind%2Fgampy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmind%2Fgampy/lists"}