hst337
Pathex - a library for performing fast actions with nested data structures
Hi there,
I’ve been working on a Pathex library for quite a while now, and I’ve finally managed to create a release which is able to cover all requirements in nested structures access. Think of Pathex as Elixir’s Access but on steroids, or like Clojure’s Spectre but easier to learn and more efficient.
Features
-
Efficient in time. It’s 2-5 times faster than
Access.HTMLmanipulations withPathexare 5 times faster thanFloki. To achieve this efficiency,Pathexgenerates pattern-matching cases at compile-time. -
Easy to use.
Pathexis like aMaporEnummodule, but for any structures. At it’s tiny core, it has everything you might need in your development needs. Errors are very descriptive. And I’ve put some effort into the documentation to be easy to navigate -
Functional.
Pathexis built around functional lens idea, but it differs in some ways from it. -
Rich toolkit.
Pathexworks fine with lists, tuples, maps, structures, nested structures like AST or HTML.Pathexis reusable, because composition of two paths creates another path and so on.
Feedback
Feedback is really appreciated. I’d like to know what you’re thinking about library design because this library tries to extend the language!
Most Liked
josevalim
krstfk
This project is really great, and it’s gonna be a dependency for all of my future projects. I’m only worried that I might end up over using it. I kind of wish there was something like this in the standard library since nested data structures are so pervasive. And I really like the fact that you can throw maps, keyword list, and tuples, nested any which way without worrying about it.
In other words, thank you!
hst337
The difference between matching and filtering is that
matching accepts pattern as a predicate. For example
iex> admin_lens = matching(%{role: :admin})
iex> Pathex.view(%User{name: "emoragaf", role: :admin}, admin_lens ~> path(:name))
{:ok, "emoragaf"}
iex> Pathex.view(%User{name: "hissssst", role: nil}, admin_lens ~> path(:name))
:error
will work only with values, which match the pattern %{role: :admin}.
And filtering lens supports any predicate as a function passed into it. For example,
iex> admin_lens = filtering(fn user -> user.role == :admin end)
iex> Pathex.view(%User{name: "emoragaf", role: :admin}, admin_lens ~> path(:name))
{:ok, "emoragaf"}
iex> Pathex.view(%User{name: "hissssst", role: nil}, admin_lens ~> path(:name))
:error
This lens does essentially the same as a matching lens above.
As you can see, every lens created with matching can be expressed with filtering, but matchingis easier to write, read and a is little bit faster than filtering
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









