{"id":15667620,"url":"https://github.com/linkdd/rustic_maybe","last_synced_at":"2025-03-30T04:26:33.754Z","repository":{"id":57545310,"uuid":"425116574","full_name":"linkdd/rustic_maybe","owner":"linkdd","description":"Maybe monad for Elixir inspired by Rust Option type","archived":false,"fork":false,"pushed_at":"2021-11-06T00:13:35.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-07T07:36:38.072Z","etag":null,"topics":["elixir","functional","maybe-monad","monad","option-type"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/linkdd.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":"2021-11-06T00:09:10.000Z","updated_at":"2021-11-06T00:28:17.000Z","dependencies_parsed_at":"2022-09-16T23:20:37.353Z","dependency_job_id":null,"html_url":"https://github.com/linkdd/rustic_maybe","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_maybe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_maybe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_maybe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_maybe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/rustic_maybe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246277252,"owners_count":20751542,"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":["elixir","functional","maybe-monad","monad","option-type"],"created_at":"2024-10-03T14:04:32.783Z","updated_at":"2025-03-30T04:26:33.733Z","avatar_url":"https://github.com/linkdd.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rustic Maybe\n\n[![CICD](https://github.com/linkdd/rustic_maybe/actions/workflows/test-suite.yml/badge.svg)](https://github.com/linkdd/rustic_maybe)\n[![Hex.pm](http://img.shields.io/hexpm/v/rustic_maybe.svg?style=flat)](https://hex.pm/packages/rustic_maybe)\n[![License](https://img.shields.io/hexpm/l/rustic_maybe)](https://github.com/linkdd/rustic_maybe/blob/main/LICENSE.txt)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/rustic_maybe/)\n\nMaybe monad for Elixir inspired by Rust\n[Option](https://doc.rust-lang.org/std/option/) type.\n\n## Installation\n\nThis package can be installed by adding `rustic_maybe` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:rustic_maybe, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\n\n```elixir\nimport Rustic.Maybe\n\nsome(1) == {:some, 1}\n# true\n\nnothing() == :nothing\n# true\n\nsome(1) |\u003e unwrap!()\n# 1\n\nnothing() |\u003e unwrap!()\n# ** (ArgumentError) trying to unwrap an empty Maybe monad\n\nsome(1) |\u003e map(fn n -\u003e n + 1 end)\n# some(2)\n\nnothing() |\u003e map(fn n -\u003e n + 1 end)\n# nothing()\n\nsome(1) |\u003e and_then(fn n -\u003e some(n + 1) end)\n# some(2)\n\nnothing() |\u003e and_then(fn n -\u003e some(n + 1) end)\n# nothing()\n\nsome(1) |\u003e or_else(fn -\u003e some(2) end)\n# some(1)\n\nnothing() |\u003e or_else(fn -\u003e some(2) end)\n# some(2)\n\nsome(1) |\u003e filter(fn n -\u003e n \u003e 0 end)\n# some(1)\n\nsome(-1) |\u003e filter(fn n -\u003e n \u003e 0 end)\n# nothing()\n\nnothing() |\u003e filter(fn n -\u003e n \u003e 0 end)\n# nothing()\n```\n\nFor more examples, please consult the\n[API reference](https://hexdocs.pm/rustic_maybe/Rustic.Maybe.html#content).\n\n\nWith function guards:\n\n```elixir\nimport Rustic.Maybe\n\ndef handle_option(val) when is_nothing(val) do\n  # ...\nend\ndef handle_option(val) when is_some(val) do\n  # ...\nend\ndef handle_result(val) do\n  raise ArgumentError, message: \"#{inspect(val)} is not a Maybe monad\"\nend\n```\n\n## Usage with Rustic.Result\n\n[Rustic.Result](https://github.com/rustic_result) is an implementation of the\nResult monad, inspired by Rust's Result type.\n\n**Result.Maybe** does not depend on **Rustic.Result** but can still work with\nits data type:\n\n```elixir\nalias Rustic.Result  # if you installed it\nalias Rustic.Maybe\n\nMaybe.some(1) |\u003e Maybe.ok_or(:no_value) == Result.ok(1)\n# true\n\nMaybe.nothing() |\u003e Maybe.ok_or(:no_value) == Result.err(:no_value)\n# true\n\nMaybe.some(Result.ok(1)) |\u003e Maybe.transpose() == Result.ok(Maybe.some(1))\n# true\n\nMaybe.some(Result.err(:no_value)) |\u003e Maybe.transpose() == Result.err(:no_value)\n# true\n\nMaybe.nothing() |\u003e Maybe.transpose() == Result.ok(Maybe.nothing())\n# true\n```\n\nFor more examples, please consult the\n[API reference](https://hexdocs.pm/rustic_maybe/Rustic.Maybe.html#content).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Frustic_maybe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Frustic_maybe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Frustic_maybe/lists"}