{"id":20400638,"url":"https://github.com/mcfilib/ribimaybe","last_synced_at":"2025-06-14T23:03:51.220Z","repository":{"id":56892223,"uuid":"20614297","full_name":"mcfilib/ribimaybe","owner":"mcfilib","description":"Maybe Functor, Applicative and Monad","archived":false,"fork":false,"pushed_at":"2018-02-07T08:23:42.000Z","size":1056,"stargazers_count":30,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-31T11:12:32.244Z","etag":null,"topics":["applicative","functor","monad","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/mcfilib.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":"2014-06-08T10:13:32.000Z","updated_at":"2021-12-28T03:44:51.000Z","dependencies_parsed_at":"2022-08-21T01:20:12.435Z","dependency_job_id":null,"html_url":"https://github.com/mcfilib/ribimaybe","commit_stats":null,"previous_names":["unsymbol/ribimaybe"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/mcfilib/ribimaybe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcfilib%2Fribimaybe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcfilib%2Fribimaybe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcfilib%2Fribimaybe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcfilib%2Fribimaybe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcfilib","download_url":"https://codeload.github.com/mcfilib/ribimaybe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcfilib%2Fribimaybe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259896128,"owners_count":22928330,"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":["applicative","functor","monad","ruby"],"created_at":"2024-11-15T04:41:54.926Z","updated_at":"2025-06-14T23:03:51.194Z","avatar_url":"https://github.com/mcfilib.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ribimaybe\n\n\u003e \"Flavouring the ocean with a teaspoon of sugar.\"\n\n[![Gem Version](https://badge.fury.io/rb/ribimaybe.svg)](http://badge.fury.io/rb/ribimaybe)\n[![Travis](https://travis-ci.org/mcfilib/ribimaybe.svg?branch=master)](http://travis-ci.org/mcfilib/ribimaybe)\n\n![](maybe.gif)\n\nA tiny Ruby library that provides a Maybe datatype which is a Functor,\nApplicative Functor and Monad.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'ribimaybe'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ribimaybe\n\n## Usage\n\nThis is a small library and so it doesn't offer lots of creature comforts. The\none escape hatch it does offer is the ability to convert `nil` into `Nothing`.\n\n``` ruby\ninclude Ribimaybe::Maybe\n\nMaybe(42)  # =\u003e Just(42)\nMaybe(nil) # =\u003e Nothing\n```\n\nAnd that's it, once you have lifted your value into a `Maybe` you can treat it\nas a `Functor`, `Applicative Functor` or `Monad`. If you want to pull your value\nout of a `Maybe`, we got you covered too.\n\n``` ruby\nJust(42).maybe(false) { |x| x == 42 } # =\u003e true\nNothing.maybe(false)  { |x| x == 42 } # =\u003e false\n```\n\n### Functor [\\[info\\]](http://learnyouahaskell.com/functors-applicative-functors-and-monoids)\n\n``` ruby\ninclude Ribimaybe::Maybe\n\n# Apply functions within Maybe and retain structure.\nJust(42).map { |x| x * x } # =\u003e Just(1764)\nNothing.map  { |x| x * x } # =\u003e Nothing\n```\n\n### Applicative Functor [\\[info\\]](http://learnyouahaskell.com/functors-applicative-functors-and-monoids)\n\n``` ruby\ninclude Ribimaybe::Maybe\n\n# Wrap functions inside functors and apply them to other functors!\nJust do |x, y|\n  x * y\nend.apply(pure(42)).apply(pure(42)) # =\u003e Just(1764)\n\nJust do |x|\n  x * x\nend.apply(Nothing) # =\u003e Nothing\n\n# We can't define \u003c*\u003e but we can define a different operator with the same\n# semantics!\nJust { |x, y| x * y } \u003e\u003e pure(42) \u003e\u003e pure(42) # =\u003e Just(1764)\n```\n\n### Monad [\\[info\\]](http://www.learnyouahaskell.com/a-fistful-of-monads)\n\n``` ruby\ninclude Ribimaybe::Maybe\n\n# Chain together computations and pretend you're a Haskeller.\nJust(42).bind do |x|\n  unit(x - 21).bind do |y|\n    if x * x \u003e 100 then unit(x) else unit(y) end\n  end\nend # =\u003e Just(42)\n\n# You guessed it! If have Nothing, you get Nothing.\nNothing.bind do |x|\n  unit(x * x)\nend # =\u003e Nothing\n\n# We even have \u003e\u003e= but it's called \u003e= and you you need to pass a Proc or a\n# lambda.\nJust(42) \u003e= -\u003e (x) do\n  unit(x - 21) \u003e= -\u003e (y) do\n    if x * x \u003e 100 then unit(x) else unit(y) end\n  end\nend # =\u003e Just(42)\n```\n\n## Contributing\n\n1. Fork it\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 new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcfilib%2Fribimaybe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcfilib%2Fribimaybe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcfilib%2Fribimaybe/lists"}