{"id":32420531,"url":"https://github.com/harehare/monad.mq","last_synced_at":"2026-07-15T07:32:08.473Z","repository":{"id":319292921,"uuid":"1073652054","full_name":"harehare/monad.mq","owner":"harehare","description":"A comprehensive monad library for mq - bringing functional programming patterns to Markdown processing.","archived":false,"fork":false,"pushed_at":"2025-10-17T12:59:24.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-25T17:54:16.989Z","etag":null,"topics":["markdown","mq"],"latest_commit_sha":null,"homepage":"https://mqlang.org","language":null,"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/harehare.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-10T12:24:52.000Z","updated_at":"2025-10-17T12:59:29.000Z","dependencies_parsed_at":"2025-10-18T18:32:21.275Z","dependency_job_id":null,"html_url":"https://github.com/harehare/monad.mq","commit_stats":null,"previous_names":["harehare/monad.mq"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/harehare/monad.mq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmonad.mq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmonad.mq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmonad.mq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmonad.mq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harehare","download_url":"https://codeload.github.com/harehare/monad.mq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmonad.mq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35496718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-15T02:00:06.706Z","response_time":131,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["markdown","mq"],"created_at":"2025-10-25T17:52:44.784Z","updated_at":"2026-07-15T07:32:08.460Z","avatar_url":"https://github.com/harehare.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# monad.mq\n\nA comprehensive monad library for [mq](https://github.com/harehare/mq) - bringing functional programming patterns to Markdown processing.\n\n\u003e [!NOTE]\n\u003e This is a hobby project exploring functional programming concepts within the mq.\n\n## Overview\n\nmonad.mq provides a collection of monadic abstractions inspired by Clojure's algo.monads library, implemented for the mq language. It enables elegant composition of computations while working with Markdown and structured data.\n\n## Features\n\n- **Multiple Monad Implementations**\n  - Identity Monad - Basic monadic structure\n  - Maybe Monad - Null-safe computations\n  - List Monad - Non-deterministic computations\n  - State Monad - Stateful computations\n  - Writer Monad - Computations with logging\n  - Reader Monad - Environment-based computations\n  - Either Monad - Error handling with Left/Right values\n- **Unified Do Notation** - `domonad` syntax for cleaner monadic composition\n- **Helper Functions** - Rich set of utilities including `m_sequence`, `m_map`, `m_comp`, `m_filter`, etc.\n- **MonadPlus Support** - Zero and plus operations for applicable monads\n\n## Quick Start\n\n### Maybe Monad - Safe Division\n\n```mq\ninclude \"monad\"\n\ndef safe_divide(a, b):\n  if (b == 0):\n    None\n  else:\n    a / b\nend\n\ndomonad(\n  maybe_m(),\n  [\n    bind(\"x\", safe_divide(10, 2)),\n    bind(\"y\", safe_divide(20, 4))\n  ],\n  fn(vars): maybe_return(vars[\"x\"] + vars[\"y\"]);\n)\n# Result: 10\n```\n\n### List Monad - Pythagorean Triples\n\n```mq\ninclude \"monad\"\n\npythagorean_triples(15)\n# Result: [[3,4,5], [6,8,10], [5,12,13], [9,12,15]]\n```\n\n### Either Monad - Error Handling\n\n```mq\ninclude \"monad\"\n\ndef parse_int(str):\n  let num = to_number(str)\n  | if (is_none(num)):\n      either_left(\"Invalid number: \" + str)\n    else:\n      either_right(num)\nend\n\ndomonad(\n  either_m(),\n  [\n    bind(\"a\", parse_int(\"42\")),\n    bind(\"b\", parse_int(\"10\"))\n  ],\n  fn(vars): either_return(vars[\"a\"] + vars[\"b\"]);\n)\n# Result: {\"type\": \"right\", \"value\": 52}\n```\n\n## Available Monads\n\n| Monad    | Purpose              | Key Functions                                         |\n| -------- | -------------------- | ----------------------------------------------------- |\n| Identity | Basic composition    | `identity_return`, `identity_bind`                    |\n| Maybe    | Null safety          | `maybe_return`, `maybe_bind`, `maybe_zero`            |\n| List     | Non-determinism      | `list_return`, `list_bind`, `list_zero`               |\n| State    | Stateful computation | `state_get`, `state_put`, `state_modify`, `run_state` |\n| Writer   | Logging              | `writer_return`, `writer_tell`                        |\n| Reader   | Environment access   | `reader_return`, `ask`, `asks`, `local`, `run_reader` |\n| Either   | Error handling       | `either_left`, `either_right`, `is_left`, `is_right`  |\n\n## Helper Functions\n\n- `m_sequence(monad_def, ms)` - Convert list of monadic values to monadic list\n- `m_map(monad_def, list, f)` - Map monadic function over list\n- `m_comp(monad_def, f, g)` - Compose monadic functions\n- `m_lift(monad_def, f)` - Lift regular function into monad\n- `m_filter(monad_def, list, pred)` - Filter with monadic predicate\n- `m_when(monad_def, condition, action)` - Conditional execution\n- `m_unless(monad_def, condition, action)` - Negated conditional execution\n\n## Examples\n\nThe library includes comprehensive examples demonstrating:\n\n1. Safe division with Maybe monad\n2. Non-deterministic pairs with List monad\n3. Counter with State monad\n4. Logging with Writer monad\n5. Error handling with Either monad\n6. Sequencing operations\n7. Function composition\n8. Pythagorean triples generation\n9. Configuration management with Reader monad\n\nSee the source code for complete example implementations.\n\n## Usage with mq\n\n```sh\n# Use the library in your mq scripts\nmq 'include \"monad\" | example_maybe()' file.md\n\n# Run with specific monad operations\nmq 'include \"monad\" | pythagorean_triples(20)' file.md\n```\n\n## Requirements\n\n- [mq](https://github.com/harehare/mq) - Command-line tool for processing Markdown\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Related\n\n- [mq](https://github.com/harehare/mq) - The mq language and CLI tool\n- [Clojure algo.monads](https://github.com/clojure/algo.monads) - Inspiration for this library\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmonad.mq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharehare%2Fmonad.mq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmonad.mq/lists"}