{"id":25424716,"url":"https://github.com/andriystr/monapy","last_synced_at":"2025-05-14T01:32:31.301Z","repository":{"id":57442855,"uuid":"327356233","full_name":"andriystr/Monapy","owner":"andriystr","description":"Python Library for declarative programming.","archived":false,"fork":false,"pushed_at":"2023-03-18T21:42:12.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-07T01:16:53.810Z","etag":null,"topics":["declarative-programming","functional-programming","library"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/monapy/","language":"Python","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/andriystr.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":"2021-01-06T15:42:00.000Z","updated_at":"2024-02-07T18:56:23.000Z","dependencies_parsed_at":"2023-01-31T03:30:30.373Z","dependency_job_id":null,"html_url":"https://github.com/andriystr/Monapy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriystr%2FMonapy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriystr%2FMonapy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriystr%2FMonapy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andriystr%2FMonapy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andriystr","download_url":"https://codeload.github.com/andriystr/Monapy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239207394,"owners_count":19599966,"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":["declarative-programming","functional-programming","library"],"created_at":"2025-02-16T23:17:26.320Z","updated_at":"2025-02-16T23:17:26.840Z","avatar_url":"https://github.com/andriystr.png","language":"Python","readme":"Monapy\n===\n\nPython Library for declarative programming.\n---\n\n### Binder - simple monad implementation.\nBinder is binding functions to chain.\nThe result of the previous function is passed to a next function as positional argument.\nRight arrows bind functions into the chain.\nLeft arrows set positional argument for last function in chain.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Binder\n\u003e\u003e\u003e binder = Binder() \u003e\u003e range \u003e\u003e map \u003c\u003c ( lambda i: i * 10 )\n\u003e\u003e\u003e list( binder( 10 ) )\n[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]\n\u003e\u003e\u003e binder \u003e\u003e filter \u003c\u003c ( lambda i: not i % 20 ) \u003e\u003e list\n\u003e\u003e\u003e binder( 10 )\n[0, 20, 40, 60, 80]\n```\n\n### Package Step\nStep is a functional unit, a step is binding with other step for making chain steps.\nClass Step must be implemented, method 'make' is main that take value and generate iterator.\nFirst step take value and generating iterator,\nthat iteratively by one values is passed other step,\nthis process continue while to the last step in the chain.\nBindings define which step the value is passed to.\nSteps may be bind by next binding methods: bind, loop_bind, or_bind.\n\n#### Bind\nThe values (in iterator) is passed to the next step.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003e\u003e Step()\n\u003e\u003e\u003e chain2 = Step().bind( Step() )\n\u003e\u003e\u003e chain3 = StepChain( [ Step(), Step() ] )\n\u003e\u003e\u003e chain4 = Step() \u003e\u003e Step() \u003e\u003e Step()\n```\n\n#### Loop\nThis bind make loop, first step's values (in iterator) is passed to second step and out of this chain,\nsecond step by each value is generating values (iterator),\nand this values is passed to first step, then all repeat until empty iterator from second step.\n```\n(iter) --\u003e value ------\u003e First Step --\u003e (iter) --\u003e value ------\u003e\n                    ^                                       |\n                    |                                       |\n                     -- value \u003c-- (iter) \u003c-- Second Step \u003c--\n```\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003c\u003c Step()\n\u003e\u003e\u003e chain2 = Step().loop( Step() )\n\u003e\u003e\u003e chain3 = LoopStep( Step(), Step() )\n```\n\n#### Or-Bind\nIt like 'or' logical expression, a first non-empty iterator is passed to out of this chain.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() | Step()\n\u003e\u003e\u003e chain2 = Step().or_bind( Step() )\n\u003e\u003e\u003e chain3 = OrChain( [ Step(), Step() ] )\n\u003e\u003e\u003e chain4 = Step() | Step() | Step()\n```\n\n#### Internal structure of chain\nTo view, how steps binded, call 'tree' method and print result.\n##### Examples:\n```python\n\u003e\u003e\u003e chain = Step() \u003e\u003e ~( Step() \u003e\u003e Step() \u003e\u003e Step() ) \u003c\u003c Step() \u003e\u003e ( Step() | Step() | Step() )\n\u003e\u003e\u003e print( chain.tree() )\nStepChain(3)\n   |__Step()\n   |__LoopStep()\n   |     |__StepChain(3)\n   |     |     |__Step()\n   |     |     |__Step()\n   |     |     |__Step()\n   |     |\n   |     |_\u003c\u003c Step()\n   |\n   |__OrChain(3)\n          |__Step()\n          |__Step()\n          |__Step()\n```\n##### Detailed tree\n```python\n\u003e\u003e\u003e print( chain.tree( full=True ) )\nStepChain(3)\n   |__Step()\n   |__LoopStep()\n   |     |__UnitedSteps()\n   |     |     |__StepChain(3)\n   |     |            |__Step()\n   |     |            |__Step()\n   |     |            |__Step()\n   |     |\n   |     |_\u003c\u003c Step()\n   |\n   |__OrChain(3)\n          |__Step()\n          |__Step()\n          |__Step()\n```\n\n#### Combining steps\nSometimes need to make a separate sub-chain, for this exists '~' expression.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = ~( Step() \u003e\u003e Step() \u003e\u003e Step() ) \u003c\u003c Step()\n\u003e\u003e\u003e print( chain1.tree() )\nLoopStep()\n   |__StepChain(3)\n   |     |__Step()\n   |     |__Step()\n   |     |__Step()\n   |\n   |_\u003c\u003c Step()\n\n\u003e\u003e\u003e chain2 = Step() \u003e\u003e Step() \u003e\u003e Step() \u003c\u003c Step()\n\u003e\u003e\u003e print( chain2.tree() )\nStepChain(3)\n   |__Step()\n   |__Step()\n   |__LoopStep()\n          |__Step()\n          |_\u003c\u003c Step()\n```\n\n#### Show UnitedSteps in tree\n```python\n\u003e\u003e\u003e print( chain1.tree( show_union=True ) )\nLoopStep()\n   |__UnitedSteps()\n   |     |__StepChain(3)\n   |            |__Step()\n   |            |__Step()\n   |            |__Step()\n   |\n   |_\u003c\u003c Step()\n```\n\n#### Run chain\nFor run chain call 'make' method, that return iterator.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain = Step() \u003e\u003e Step() \u003c\u003c Step() \u003e\u003e ( Step() | Step() | Step() )\n\u003e\u003e\u003e for val in chain.make( value ):\n\u003e\u003e\u003e     print( val )\n\n\u003e\u003e\u003e for val in chain( value ):\n\u003e\u003e\u003e     print( val )\n```\n\n#### Packing values in standard data structures\n4 structures supported: tuple, list, dict, set.\nValues pack the corresponding steps,\nto create this step need bind the chain with corresponding structure of steps,\nor call a corresponding class.\nFrom each step, one value is taken and pack into structure.\n##### Pack in tuple\n\u003e It's like 'zip' function,\n\u003e if every step returns a value then those values ​​are packed into a tuple,\n\u003e otherwise no packing happens and values ​​aren't returned.\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003e\u003e ( Step(), Step(), Step() )\n\u003e\u003e\u003e chain2 = TupleStep( ( Step(), Step(), Step() ) )\n\u003e\u003e\u003e chain3 = to_step( ( Step(), Step(), Step() ) )\n```\n##### Pack in list\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003e\u003e [ Step(), Step(), Step() ]\n\u003e\u003e\u003e chain2 = ListStep( [ Step(), Step(), Step() ] )\n\u003e\u003e\u003e chain3 = to_step( [ Step(), Step(), Step() ] )\n```\n##### Pack in dict\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003e\u003e { 'key1': Step(), 'key2': Step(), 'key3': Step() }\n\u003e\u003e\u003e chain2 = DictStep( { 'key1': Step(), 'key2': Step(), 'key3': Step() } )\n\u003e\u003e\u003e chain3 = to_step( { 'key1': Step(), 'key2': Step(), 'key3': Step() } )\n```\n##### Pack in set\n##### Examples:\n```python\n\u003e\u003e\u003e from monapy import Step\n\u003e\u003e\u003e chain1 = Step() \u003e\u003e { Step(), Step(), Step() }\n\u003e\u003e\u003e chain2 = SetStep( { Step(), Step(), Step() } )\n\u003e\u003e\u003e chain3 = to_step( { Step(), Step(), Step() } )\n```\n\n#### Step class implementation\nClass Step has two methods to implement,\nit's 'make' and 'make_all'.\nThe 'make' method takes a value and generates an iterator,\nthat is passed to the next step.\nThis method takes one positional argument to get the value,\nand also accepts named arguments,\nthat are used to pass settings for all steps in the chain.\nThe method 'make_all' is taking an iterator of values that it passes to the 'make' method,\nit could be used for paralleling.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriystr%2Fmonapy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandriystr%2Fmonapy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriystr%2Fmonapy/lists"}