{"id":27331998,"url":"https://github.com/tap349/hayase","last_synced_at":"2025-04-12T13:46:33.073Z","repository":{"id":57504507,"uuid":"180793393","full_name":"tap349/hayase","owner":"tap349","description":"Simple monads for Elixir","archived":false,"fork":false,"pushed_at":"2021-06-08T06:22:18.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-18T07:07:00.962Z","etag":null,"topics":["elixir","monad"],"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/tap349.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-11T13:03:00.000Z","updated_at":"2024-04-18T07:07:00.963Z","dependencies_parsed_at":"2022-08-30T03:41:27.349Z","dependency_job_id":null,"html_url":"https://github.com/tap349/hayase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tap349%2Fhayase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tap349%2Fhayase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tap349%2Fhayase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tap349%2Fhayase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tap349","download_url":"https://codeload.github.com/tap349/hayase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248574960,"owners_count":21127094,"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","monad"],"created_at":"2025-04-12T13:46:27.206Z","updated_at":"2025-04-12T13:46:33.065Z","avatar_url":"https://github.com/tap349.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hayase\n\nSimple implementation of common ADTs (`Maybe`, `Result`) and their instances\nof `Functor` and `Monad` typeclasses in Elixir.\n\nThis package is based on [towel](https://github.com/knrz/towel) package but\nmodifies and extends it in a few ways:\n\n- add `Hayase.Maybe.unwrap/2` to provide fallback value (just like\n  `Algae.Maybe.from_maybe/2` from `algae` package)\n- `unwrap` functions from both `Maybe` and `Result` ADTs don't unwrap\n  passed values recursively but do it one level deep only\n- return value of `Hayase.Functor.fmap/2` is always constructed with\n  the same type constructor as input value\n- implement an instance of `Functor` typeclass for Elixir maps\n\n`hayase` package is not meant to replace other packages providing algebraic\nand categorical abstractions - it aims to implement a small subset of their\nfunctionality which seems to be enough for my needs.\n\n## Examples\n\nUsing `Hayase.Types.Maybe` - before processing it's useful to wrap input value\nwith `Hayase.Types.Maybe.wrap/1` to build `Maybe` value automatically:\n\n```elixir\nuse Hayase\n\n# -----------------------------------------------\n# using with `Hayase.Typeclasses.Functor.fmap/2`\n# -----------------------------------------------\n\n\"foo\"\n|\u003e Maybe.wrap()\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" bar\" end)\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" baz\" end)\n# =\u003e {:just, \"foo bar baz\"}\n\nnil\n|\u003e Maybe.wrap()\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" bar\" end)\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" baz\" end)\n# =\u003e :nothing\n\n# -----------------------------------------------\n# using with `Hayase.Typeclasses.Monad.bind/2`\n# -----------------------------------------------\n\n\"foo\"\n|\u003e Maybe.wrap()\n|\u003e bind(fn x -\u003e Maybe.just(x \u003c\u003e \" bar\") end)\n|\u003e bind(fn x -\u003e Maybe.just(x \u003c\u003e \" baz\") end)\n# =\u003e {:just, \"foo bar baz\"}\n\n\"foo\"\n|\u003e Maybe.wrap()\n|\u003e bind(fn x -\u003e Maybe.just(x \u003c\u003e \" bar\") end)\n|\u003e bind(fn x -\u003e Maybe.nothing(x \u003c\u003e \" baz\") end)\n# =\u003e :nothing\n\nnil\n|\u003e Maybe.wrap()\n|\u003e bind(fn x -\u003e Maybe.just(x \u003c\u003e \" bar\") end)\n|\u003e bind(fn x -\u003e Maybe.just(x \u003c\u003e \" baz\") end)\n# =\u003e :nothing\n\n# -----------------------------------------------\n# unwrapping\n# -----------------------------------------------\n\n{:just, \"foo bar baz\"}\n|\u003e Maybe.unwrap()\n# =\u003e \"foo bar baz\"\n\n:nothing\n|\u003e Maybe.unwrap()\n# =\u003e nil\n\n:nothing\n|\u003e Maybe.unwrap(\"fallback value\")\n# =\u003e \"fallback value\"\n```\n\nUsing `Hayase.Types.Result` - as a rule it's not necessary to wrap input value\nwith `Hayase.Types.Result.wrap/1` since in most cases it's already provided as\na `Result` value (so called tagged tuple):\n\n```elixir\nuse Hayase\n\n# -----------------------------------------------\n# using with `Hayase.Typeclasses.Functor.fmap/2`\n# -----------------------------------------------\n\n{:ok, \"foo\"}\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" bar\" end)\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" baz\" end)\n# =\u003e {:ok, \"foo bar baz\"}\n\n{:error, \"error\"}\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" bar\" end)\n|\u003e fmap(fn x -\u003e x \u003c\u003e \" baz\" end)\n# =\u003e {:error, \"error\"}\n\n# -----------------------------------------------\n# using with `Hayase.Typeclasses.Monad.bind/2`\n# -----------------------------------------------\n\n{:ok, \"foo\"}\n|\u003e bind(fn x -\u003e Result.ok(x \u003c\u003e \" bar\") end)\n|\u003e bind(fn x -\u003e Result.ok(x \u003c\u003e \" baz\") end)\n# =\u003e {:ok, \"foo bar baz\"}\n\n{:ok, \"foo\"}\n|\u003e bind(fn x -\u003e Result.error(x \u003c\u003e \"error\") end)\n|\u003e bind(fn x -\u003e Result.ok(x \u003c\u003e \" baz\") end)\n# =\u003e {:error, \"error\"}\n\n# -----------------------------------------------\n# unwrapping\n# -----------------------------------------------\n\n{:ok, \"foo bar baz\"}\n|\u003e Result.unwrap()\n# =\u003e \"foo bar baz\"\n\n{:error, \"error\"}\n|\u003e Result.unwrap()\n# =\u003e \"error\"\n```\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `hayase` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:hayase, \"~\u003e 0.1\"}\n  ]\nend\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/hayase](https://hexdocs.pm/hayase).\n\n## TODO\n\n- tests\n- typespecs\n- docs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftap349%2Fhayase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftap349%2Fhayase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftap349%2Fhayase/lists"}