{"id":18000132,"url":"https://github.com/jmargenberg/monok","last_synced_at":"2025-04-04T07:43:59.933Z","repository":{"id":62429904,"uuid":"161763984","full_name":"jmargenberg/monok","owner":"jmargenberg","description":"Alternative pipe operators for clean handling of `{:ok, value}` and `{:error, reason}` tuples in Elixir","archived":false,"fork":false,"pushed_at":"2018-12-23T09:48:45.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-11T16:49:52.511Z","etag":null,"topics":["elixir","functional-programming"],"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/jmargenberg.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}},"created_at":"2018-12-14T09:43:56.000Z","updated_at":"2023-06-16T07:27:26.000Z","dependencies_parsed_at":"2022-11-01T20:03:28.488Z","dependency_job_id":null,"html_url":"https://github.com/jmargenberg/monok","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/jmargenberg%2Fmonok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2Fmonok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2Fmonok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmargenberg%2Fmonok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmargenberg","download_url":"https://codeload.github.com/jmargenberg/monok/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142043,"owners_count":20890652,"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-programming"],"created_at":"2024-10-29T23:09:46.014Z","updated_at":"2025-04-04T07:43:59.912Z","avatar_url":"https://github.com/jmargenberg.png","language":"Elixir","readme":"# Monok\n[![Build Status](https://travis-ci.org/jmargenberg/monok.svg?branch=master)](https://travis-ci.org/jmargenberg/monok) [![Coverage Status](https://coveralls.io/repos/github/jmargenberg/monok/badge.svg?branch=master)](https://coveralls.io/github/jmargenberg/monok?branch=master) [![Hex.pm](https://img.shields.io/hexpm/v/monok.svg)](https://hex.pm/packages/monok)\n\n#### _Monad on :ok_\n\nProvides the infix pipe operators `~\u003e`, `~\u003e\u003e`, and `\u003c~\u003e` for writing clean pipelines that treat `{:ok, result}`\nand `{:error, reason}` tuples like functors, monads or applicatives.\n\nAlso provides the functions `fmap`, `bind` and `lift` as which are functionally identical but are less cryptic and\ncan be used without overriding any inifix operators which could potentially conflict with other libraries.\n\n## Why would you ever do this?\n\nWhilst writing unnecessary macros and overriding infix operators are both generally considered bad practice I\nthought I'd try this out given just how freqently `{:ok, result}` and `{:error, reason}` tuples are encountered\nin Elixir.\n\n## Functor Pipelines\n\nAllows you to write clean pipelines that transforms values inside of `{:ok, value}` tuples.\n\n```\niex\u003e {:ok, [1, 2, 3]}\n...\u003e ~\u003e Enum.sum()\n...\u003e ~\u003e div(2)\n{:ok, 3}\n```\n\nIf the input is an `{:error, reason}` tuple it is carried through the pipeline without applying any\ntransformations.\n\n```\niex\u003e {:error, :reason}\n...\u003e ~\u003e Enum.sum()\n...\u003e ~\u003e div(2)\n{:error, :reason}\n```\n\n## Monad Pipelines\n\nAllows you to write clean pipelines that transform values in `{:ok, value}` tuples with functions that also\nreturn `{:ok, value}` tuples.\n\n```\niex\u003e decrement = fn\n...\u003e   x when x \u003e 0 -\u003e {:ok, x - 1}\n...\u003e   _ -\u003e {:error, :input_too_small}\n...\u003e  end\niex\u003e {:ok, 3}\n...\u003e ~\u003e\u003e decrement.()\n...\u003e ~\u003e\u003e decrement.()\n{:ok, 1}\n```\n\nIf at any point in the pipeline an `{:error, reason}` tuple is returned it is carried through without\nany of the transformation functions being applied.\n\n```\niex\u003e decrement = fn\n...\u003e   x when x \u003e 0 -\u003e {:ok, x - 1}\n...\u003e   _ -\u003e {:error, :input_too_small}\n...\u003e  end\niex\u003e\n...\u003e {:ok, 3}\n...\u003e ~\u003e\u003e (fn _ -\u003e {:error, :contrived_example} end).()\n...\u003e ~\u003e\u003e decrement.()\n...\u003e ~\u003e\u003e decrement.()\n{:error, :contrived_example}\n```\n\n## Mixed Pipelines\n\nThese pipe operators don't have to be used in seperate pipelines but can be used together or even with the `|\u003e`\nstandard pipe operator.\n\n```\niex\u003e 7\n...\u003e |\u003e (\u0026(if \u00261 \u003e 5, do: {:ok, \u00261}, else: {:error, :too_low})).()\n...\u003e ~\u003e Integer.to_string()\n...\u003e ~\u003e\u003e (\u0026(if \u00261 |\u003e String.length() \u003e 0, do: {:ok, \u00261 \u003c\u003e \"!\"}, else: {:error, :empty_string})).()\n{:ok, \"7!\"}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmargenberg%2Fmonok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmargenberg%2Fmonok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmargenberg%2Fmonok/lists"}