hst337
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!
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #security
- #elixirconf-eu
- #api
- #forms
- #hex










Showing Posts 22 to 13- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Asd
Here you go
And try it out with this
A few words about this cryptic thing
I know that
combineis hard to get correctly from the first try, especially when combined with logical operators (like|||), but my advise here is to always think of it as of a recursive tree traversal.Once you get into the node, it might be the node you were looking for (hence the
matching(%{id: ^post_id}), but if it is not (hence the|||), you need to check it’s children. First you need to find where the children are (underchildrenkey, hense thepath(:children)), then you need to traverse all children or just some (here I assume we can encounter post with id=4 only once, so we need to find the single one, hence we do~> some()), and then you need to treat them just like you did (hence the~> recursive)BrightEyesDavid
This section of the docs shows what I think I’m after, but I’m rather lost and have not managed to replace any nested value yet.
I have a nested structure of unknown levels, generated from Ecto results and Arbor. Simplified:
There’s always one root Post struct.
I need to update a couple of keys’ values (e.g.,
:show_reply_formtotrue) for the potentially nested struct/map that has a givenid. Theidis coming from a user-triggered LiveView event value.As part of stumbling through, it seemed as if I needed to change this line from the documentation:
to the following in order to avoid errors:
Here’s what I’m trying:
It’s not erroring, but nothing is replaced.
I do have my own (probably horrible) function that’s working, but I think it’s not memory-efficient and runs through more of the posts than necessary:
So I thought I’d see if I could use Pathex. But I’m very open to using a better function than mine, too.
Thanks.
Asd
Try using Pathex.at/3 like this
RemyXRenard
I hope it’s okay to resurrect this thread. I have a quick question about Pathex. I feel like I may be missing something simple.
If I have a map → list → map structure, is there a way to return multiple keys from the inner map?
e.g.
The above returns
[%{foo: "bar", foo2: "bar", foo3: "'baz"}, %{foo: "baz", foo2: "fizz", foo3: "baz"}]Can I return the values for :foo and :foo2 but not foo3? Is it only matching on the value?
I can add
|> Enum.flat_map(& Map.take(&1, [:foo, :foo2]))to get what I need, just checking that I’m not missing some magic in the match.hst337
Pathex 2.5.0 release
This release contains performance improvements, bug fixes and special functions for creating
for_update-friendly lenses for structures and records. For more information, refer to changelogFor example,
This is useful for doing deeply nested
force_setandforce_updateoperationshst337
Pathex 2.4.0 release
This release contains bug fixes and improvements in negative indexes for lists and tuples and improvements for
force_*operations. For more information, refer to changelogFor example, force_setting a value in list used to result in something like
And now the empty space is filled with
nillike thishst337
Pathex 2.3 release is here
Nothing special, just
Pathex.Shortfor shorter path definition. One can use just:x / : yinstead ofpath :x / :ywhen usingPathex.ShortPathex.patternfor creating patterns from inlined paths. For example,Pathexnow can beuse-d inside functions or anything like this. This is now tested and supported.Macro.Env.lookup*functions, therefore pathex is compatible only with elixir 1.13 or higherBy the way, I’ve tested this release against
gradient(from gradualizer project) and it seemed to be able to find some errors in specs, while failing to complete checking with exception and a bunch of false positives. And I’ve used mix_unused tool to find some unused functions (which helped me a lot)hst337
Hi, I’ve just released 2.2.0, you can now use this function:
hst337
Yeah, that’s a good idea. I already have this in my TODO list, I’ll try to prioritize it for 2.2 or 2.3 versions then.
egze
Thanks. Missed the
matching/1Do you think there’s a room for
Pathex.new/1?Thinking about:
I would be heppy to contribute. I get the compile time benefits, but sometimes it’s the way it is