{"id":13483667,"url":"https://github.com/alex-lairan/monads","last_synced_at":"2026-01-18T09:20:51.568Z","repository":{"id":53475955,"uuid":"153018655","full_name":"alex-lairan/monads","owner":"alex-lairan","description":"Monads for Crystal","archived":false,"fork":false,"pushed_at":"2026-01-17T13:35:46.000Z","size":148,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2026-01-17T22:33:13.868Z","etag":null,"topics":["crystal","crystal-language","monads"],"latest_commit_sha":null,"homepage":"https://github.com/alex-lairan/monads","language":"Crystal","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/alex-lairan.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":"2018-10-14T21:02:02.000Z","updated_at":"2026-01-17T13:35:48.000Z","dependencies_parsed_at":"2023-01-19T23:10:30.207Z","dependency_job_id":null,"html_url":"https://github.com/alex-lairan/monads","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/alex-lairan/monads","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-lairan%2Fmonads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-lairan%2Fmonads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-lairan%2Fmonads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-lairan%2Fmonads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex-lairan","download_url":"https://codeload.github.com/alex-lairan/monads/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-lairan%2Fmonads/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28534158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":["crystal","crystal-language","monads"],"created_at":"2024-07-31T17:01:13.977Z","updated_at":"2026-01-18T09:20:46.556Z","avatar_url":"https://github.com/alex-lairan.png","language":"Crystal","funding_links":[],"categories":["Misc"],"sub_categories":[],"readme":"# monads\n[![Build Status](https://travis-ci.org/alex-lairan/monads.svg?branch=master)](https://travis-ci.org/alex-lairan/monads)\n\nMonads for Crystal.\n\nInspired by https://github.com/dry-rb/dry-monads\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  monads:\n    github: alex-lairan/monads\n```\n\n## Usage\n\n```crystal\nrequire \"monads\"\n```\n\nMany monads exist.\n\n### Maybe(T)\n\nThe *Maybe* monad helps to avoid `nil` and chain instructions.\n\nThere are two kinds of *Maybe*, `Just` and `Nothing`.\n\n#### Just(T)\n\nThis is just a value.\n\n```crystal\nMonads::Just.new(5)\n```\n\n#### Nothing(T)\n\nThis is an absence of value.\n\n```crystal\nMonads::Nothing(Int32).new\n```\n\n### Either(E, T)\n\nThe *Either* monad helps to manage *errors* at the end of the chain of instructions.\n\nThere are two kinds of *Either*, `Right` and `Left`.\n\n#### Right(T)\n\nThis is just a value.\n\n```crystal\nMonads::Right.new(\"Hello world\")\n```\n\n#### Left(E)\n\nThis is an error.\n\n```crystal\nMonads::Left.new(\"User password is incorrect\")\n```\n\n### List(T)\n\nThe *List* monad helps to manipulate an *Array* like a monad.\n\n```crystal\nMonads::List[1, 6, 4, 2]\n```\n\n#### head\n\n`head` returns the first element wrapped within a `Maybe`.\n\n#### tail\n\n`tail` returns the list without the first element.\n\n### Try(T)\n\nThe `Try` monad is a layer between *Object Oriented Exception* and *Fuctional Programming Monads*.\nIt can be transformed into a `Maybe` or an `Either`.\n\n### Task(T)\n\nThe `Task` monad is a parallelized `Try` monad.\nIts goal is to use the power of fibers with monads.\n\n### How to use a monad ?\n\nMonads have some methods which help to chain instructions.\n\n`Try` and `Task` monads should be translated into a `Maybe(T)` or an `Either(Exception, T)` one.\n\n#### fmap\n\nThe `fmap` procedure modify the internal value of a monad.\n\nThis doesn't affect `Nothing` and `Left` monads.\n\nExample:\n\n```crystal\nvalue = Monads::Just.new(5)\n  .fmap(-\u003e(x : Int32) { x.to_s })\n  .fmap(-\u003e(x : String) { x + \"12\" })\n  .fmap(-\u003e(x : String) { x.to_i })\n  .value!\nvalue.should eq(512)\n```\n\n#### bind\n\nThe `bind` procedure allows to create a whole new monad from the internal data of another.\n\nThis doesn't affect `Nothing` and `Left` monads.\n\nExample:\n\n```crystal\nvalue = Monads::Just.new(5)\n  .bind(-\u003e(x : Int32) { Monads::Try(Int32).new(-\u003e { x / 0}).to_maybe })\nvalue.should eq(Monads::Nothing(Int32).new)\n```\n\n## Development\n\nClone then let's go, no special requirements.\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/alex-lairan/monads/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [alex-lairan](https://github.com/alex-lairan) Alexandre Lairan - creator, maintainer\n- [moba1](https://github.com/moba1) moba - maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-lairan%2Fmonads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex-lairan%2Fmonads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-lairan%2Fmonads/lists"}