{"id":18257928,"url":"https://github.com/linkdd/rustic_result","last_synced_at":"2025-07-16T08:06:53.616Z","repository":{"id":57545319,"uuid":"418674501","full_name":"linkdd/rustic_result","owner":"linkdd","description":"Result monad for Elixir inspired by Rust Result type","archived":false,"fork":false,"pushed_at":"2024-02-15T08:44:05.000Z","size":36,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-15T09:22:22.355Z","etag":null,"topics":["elixir","functional","monad","result-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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-18T21:30:09.000Z","updated_at":"2024-02-09T02:06:51.000Z","dependencies_parsed_at":"2024-11-05T10:56:28.189Z","dependency_job_id":null,"html_url":"https://github.com/linkdd/rustic_result","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"3f812368f5c8ba2e13c2735050b7214d99711a43"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Frustic_result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/rustic_result/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229376,"owners_count":20905039,"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","monad","result-type"],"created_at":"2024-11-05T10:28:11.963Z","updated_at":"2025-04-04T18:31:23.964Z","avatar_url":"https://github.com/linkdd.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rustic Result\n\n[![CICD](https://github.com/linkdd/rustic_result/actions/workflows/test-suite.yml/badge.svg)](https://github.com/linkdd/rustic_result)\n[![Hex.pm](http://img.shields.io/hexpm/v/rustic_result.svg?style=flat)](https://hex.pm/packages/rustic_result)\n[![License](https://img.shields.io/hexpm/l/rustic_result)](https://github.com/linkdd/rustic_result/blob/main/LICENSE.txt)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/rustic_result/)\n\nResult monad for Elixir inspired by Rust\n[Result](https://doc.rust-lang.org/std/result/) type.\n\n## Installation\n\nThis package can be installed by adding `rustic_result` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:rustic_result, \"~\u003e 0.6.1\"}\n  ]\nend\n```\n\n## Usage\n\n**NB:** `:ok` is treated as `{:ok, nil}`\n\n```elixir\nimport Rustic.Result\n\nok(42) == {:ok, 42}\n# true\n\nerr(:not_found) == {:error, :not_found}\n# true\n\n:ok |\u003e ok?()\n# true\n\nok(42) |\u003e ok?()\n# true\n\nerr(:not_found) |\u003e err?()\n# true\n\nok(1) |\u003e map(fn v -\u003e v + 1 end)\n# ok(2)\n\n:ok |\u003e map(fn nil -\u003e 1 end)\n# ok(1)\n\nerr(:not_found) |\u003e map(fn v -\u003e v + 1 end)\n# err(:not_found)\n\nok(1) |\u003e map_err(fn reason -\u003e {:failed, reason} end)\n# ok(1)\n\nerr(:not_found) |\u003e map_err(fn reason -\u003e {:failed, reason} end)\n# err({:failed, :not_found})\n\nok(1) |\u003e and_then(fn v -\u003e ok(v + 1) end)\n# ok(2)\n\n:ok |\u003e and_then(fn nil -\u003e ok(1) end)\n# ok(1)\n\nok(1) |\u003e and_then(fn _ -\u003e err(:not_found) end)\n# err(:not_found)\n\nerr(:not_found) |\u003e and_then(fn v -\u003e ok(v + 1) end)\n# err(:not_found)\n\nok(1) |\u003e or_else(fn _ -\u003e ok(2) end)\n# ok(1)\n\nerr(:not_found) |\u003e or_else(fn :not_found -\u003e ok(1) end)\n# ok(1)\n\nerr(:not_found) |\u003e or_else(fn :not_found -\u003e err(:invalid) end)\n# err(:invalid)\n\nok(1) |\u003e unwrap!()\n# 1\n\n:ok |\u003e unwrap!()\n# nil\n\nerr(:not_found) |\u003e unwrap!()\n# ** (Rustic.Result.UnhandledError) Expected an Ok result, \":not_found\" given.\n\nok(1) |\u003e unwrap_or(2)\n# 1\n\n:ok |\u003e unwrap_or(1)\n# nil\n\nerr(:not_found) |\u003e unwrap_or(2)\n# 2\n\nok(1) |\u003e unwrap_err!()\n# ** (Rustic.Result.MissingError) Expected an Err result, \"1\" given.\n\nerr(:not_found) |\u003e unwrap_err!()\n# :not_found\n\nok(ok(1)) |\u003e flatten()\n# ok(1)\n\nok(err(:failed)) |\u003e flatten()\n# err(:failed)\n\nok(1) |\u003e flatten()\n# ok(1)\n\n[ok(1), ok(2)] |\u003e collect()\n# ok([1, 2])\n\n[ok(1), err(:not_found)] |\u003e collect()\n# err(:not_found)\n\n[ok(1), err(:not_found)] |\u003e filter_collect()\n# ok([1])\n\n[ok(1), err(:not_found)] |\u003e partition_collect()\n# {ok([1]), err([:not_found])}\n```\n\nWith function guards:\n\n```elixir\nimport Rustic.Result\n\ndef handle_result(val) when is_ok(val) do\n  # ...\nend\ndef handle_result(val) when is_err(val) do\n  # ...\nend\ndef handle_result(val) do\n  raise ArgumentError, message: \"#{inspect(val)} is not a result\"\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Frustic_result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Frustic_result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Frustic_result/lists"}