{"id":13508545,"url":"https://github.com/hissssst/pathex","last_synced_at":"2025-05-16T03:02:11.906Z","repository":{"id":39647647,"uuid":"257865772","full_name":"hissssst/pathex","owner":"hissssst","description":"Fastest tool to access data in Elixir","archived":false,"fork":false,"pushed_at":"2024-07-29T10:14:42.000Z","size":295,"stargazers_count":353,"open_issues_count":2,"forks_count":17,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-08T13:19:10.811Z","etag":null,"topics":["elixir","lens","lenses","macros","nested-structures"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hissssst.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-04-22T10:19:27.000Z","updated_at":"2025-05-06T00:46:01.000Z","dependencies_parsed_at":"2023-01-29T01:15:23.148Z","dependency_job_id":"4819ad9a-4ec9-478d-9b84-528c453e13a7","html_url":"https://github.com/hissssst/pathex","commit_stats":{"total_commits":86,"total_committers":9,"mean_commits":9.555555555555555,"dds":0.2093023255813954,"last_synced_commit":"230bdf0d03e111d2fdb95369e72936c2905539c8"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hissssst%2Fpathex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hissssst%2Fpathex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hissssst%2Fpathex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hissssst%2Fpathex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hissssst","download_url":"https://codeload.github.com/hissssst/pathex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459077,"owners_count":22074604,"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","lens","lenses","macros","nested-structures"],"created_at":"2024-08-01T02:00:54.589Z","updated_at":"2025-05-16T03:02:11.889Z","avatar_url":"https://github.com/hissssst.png","language":"Elixir","funding_links":[],"categories":["Macros"],"sub_categories":[],"readme":"# Pathex\n\nSpeed or composability? Choose both!\n\n## Elixir 1.17 warning\n\nIt turns out that Elixir 1.17 release has 3 bugs which block reliable usage of Pathex library, one of which is critical.\nSo please, do not use Elixir 1.17 with the Pathex library. However, these issues are fixed in upcoming Elixir 1.18 release.\n\n### What is Pathex?\n\nPathex is a library for performing fast actions with nested data structures in Elixir.\nWith pathex you can trivially set, get and update values in structures in a functional manner.\nIt provides all necessary logic to manipulate data structures in different ways using flexible __functional lens__ pattern.\n\n### Why another library?\n\nExisting methods of accesssing data in nested structures are either slow (like `Focus`) or do not provide enough functionality (like `Access`). For example setting the value in structure with Pathex is `70-160x` faster than `Focus` or `2-3x` faster than `put_in` and `get_in`\n\n\u003e You can checkout benchmarks at https://github.com/hissssst/pathex_bench\n\n## Usage\n\nPathex is really simple and straightforward to use (almost like `Enum`). You don't need to learn any specific language, just create paths with `path` and use verbs with them.\n\n### Add it to your module\n\n```elixir\n# This will import path macro and operators and require Pathex\nuse Pathex\n```\n\n\u003e Or just `import Pathex`\n\n### Create the path\n\n```elixir\npath_to_streets = path :user / :private / :addresses / 0 / :street\npath_in_json = path \"users\" / 1 / \"street\", :json\n```\n\nThis creates closure which can get, set, update and delete values in this path\n\n### Use the path\n\n```elixir\n{:ok, \"6th avenue\" = street} =\n  %{\n    user: %{\n      id: 1,\n      name: \"hissssst\",\n      private: %{\n        phone: \"123-456-789\",\n        addresses: [\n           [city: \"City\", street: \"6th avenue\", mail_index: 123456]\n        ]\n      }\n    }\n  }\n  |\u003e Pathex.view(path_to_streets)\n\n%{\n  \"users\" =\u003e %{\n    1 =\u003e %{\"street\" =\u003e \"6th avenue\"}\n  }\n} = Pathex.force_set!(%{}, path_in_json, street)\n```\n\n## Features\n\nPathex has a lot of different features and can even compete with code written by hand in terms of efficiency.\nPathex significantly reduces the time to write a code which manipulates nested structure, while\nproviding efficiency and composability. No more functions like `get_users`, `set_users`, `update_users`! No more XPaths, JSONPaths, CSS Selectors!\n\n### Easy to use\n\nIt's not harder to use than `Map` or `Enum`! Check out the [cheatsheet](https://hexdocs.pm/pathex/cheatsheet.html) for common tasks.\n\nPathex also provides more information about errors than any other tool.\n\n```elixir\niex(1)\u003e field = :email\niex(2)\u003e Pathex.view!(%{}, path(:users) ~\u003e all() ~\u003e path(:personal / field))\n** (Pathex.Error)\n  Couldn't find element\n\n    Path:      path(:users) ~\u003e all() ~\u003e path(:personal / :email)\n\n    Structure: %{}\n```\n\n### Fast\n\nPaths are just a set of pattern-matching cases.\nThis is done to extract maximum efficiency from BEAM's pattern-matching compiler.\n\n```elixir\n# Code for viewing variables for path\npath(1 / \"y\", :map)\n\n# Almost equals to\ncase input do\n  %{1 =\u003e %{\"y\" =\u003e res}} -\u003e\n    {:ok, res}\n\n  _ -\u003e\n    :error\nend\n```\n\n### Reusable\n\nOne path can be used to update, get, set, delete or update a value in the structure!\nAnd these paths can even be composed together.\nThis composition is very efficient, there's no need to concatenate lists like `Access` does.\n\n```elixir\n# User structure\nuser = %User{\n  personal: %{fname: \"Kabs\", sname: \"Rocks\"},\n  phone: \"123-456-789\"\n}\n\n# Path to username in user structure\nusername = path(:personal / :fname)\n\n# Get a username\n{:ok, \"Kabs\"} = Pathex.view(user, username)\n\n# Set a username\nanother_user =\n  %User{\n    personal: %{fname: \"Blabs\", sname: \"Rocks\"},\n    phone: \"123-456-789\"\n  } = Pathex.set!(user, username, \"Blabs\")\n\n# Get all usernames!\nimport Pathex.Lenses\n[\"Kabs\", \"Blabs\"] =\n  [\n    user,\n    another_user\n  ]\n  |\u003e Pathex.view!(all() ~\u003e username)\n```\n\nPathex can be used to manipulate different nested data structures. From `GenServer` state to HTML or Elixir's AST!\n\n### Extensible\n\nPathex is built around simple primitive called `path-closure`, which is a simple closure with clearly defined specification. Anything complying with `Pathex.t()` spec can be used within `Pathex`.\n\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:pathex, \"~\u003e 2.0\"}\n  ]\nend\n```\n\n\u003e Pathex is significantly faster with OTP 26\n\n## Contributions\n\nWelcome! If you want to get your hands dirty, you can check existing `TODO`'s.\n\n\u003e **By the way**\n\u003e\n\u003e If you have any suggestions or want to change something in this library don't hesitate to open an issue. If you have any whitepapers about functional lenses, you can add them in a PR to the bottom of this readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhissssst%2Fpathex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhissssst%2Fpathex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhissssst%2Fpathex/lists"}