hst337

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

  1. Efficient in time. It’s 2-5 times faster than Access. HTML manipulations with Pathex are 5 times faster than Floki. To achieve this efficiency, Pathex generates pattern-matching cases at compile-time.

  2. Easy to use. Pathex is like a Map or Enum module, 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

  3. Functional. Pathex is built around functional lens idea, but it differs in some ways from it.

  4. Rich toolkit. Pathex works fine with lists, tuples, maps, structures, nested structures like AST or HTML. Pathex is 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!

https://hexdocs.pm/pathex/readme.html

Most Liked

josevalim

josevalim

Creator of Elixir

Great project and documentation!

17
Post #2
krstfk

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

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

hst337

hst337

Hi, I’ve just released 2.2.0, you can now use this function:
https://hexdocs.pm/pathex/Pathex.Accessibility.html#from_list/2

hst337

hst337

Pathex 2.3 release is here :tada:

Nothing special, just

  1. Pathex.Short for shorter path definition. One can use just :x / : y instead of path :x / :y when using Pathex.Short
  2. Pathex.pattern for creating patterns from inlined paths. For example,
use Pathex, default_mod: :json
import Pathex

pattern(four, path :x / :y / :z / 3) = %{x: %{y: %{z: [1, 2, 3, 4]}}}
  1. Pathex now can be use-d inside functions or anything like this. This is now tested and supported.
  2. Paths inlining is now detected for aliased, imported and macro calls. This is done using Macro.Env.lookup* functions, therefore pathex is compatible only with elixir 1.13 or higher
  3. Spec fixes here and there, project formatting.

By 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)

Where Next?

Popular in Libraries Top

josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 18262 141
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Sub Categories:

We're in Beta

About us Mission Statement