hst337

hst337 OP

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://github.com/hissssst/pathex

First 10 of 22 Posts Switch mode

josevalim

josevalim

Creator of Elixir

Great project and documentation!

17
Post #1
Will-W

Will-W

This looks great and I already have some use cases for it.

I like the design too - like the separation of the definition of the paths. I can see it would allow for cleaner code: separation of the definition of the structure of your data from the code that manipulates it.

emoragaf

emoragaf

This looks awesome, great work!

I was looking at the Lenses docs and it wasn’t really clear to me the difference between matching and filtering (both the description and the examples are exactly the same)

Doc content in general is really good, but maybe some reordering could be helpful to clarify some things, e.g: cover the combinator syntax before the examples in the cheat sheet.

hst337

hst337 OP

Thanks, I’ll a basic syntax in the Cheatsheet

hst337

hst337 OP

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

alex_r

alex_r

Loving this. I work with deep (up to 10 levels) sports stats data and this could be my ticket to code reduction. Thanks!

l3nz

l3nz

Spectre is/was a great idea, though it did not get the adoption it deserved. Not very easy to get started with.

Pathex seems to be an improvement - I was looking for something like that myself, because working with immutable nested structures is a pain.

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!

thisiscetin

thisiscetin

Just tweeted about it from theelixirbook account.

Great job, kudos.

hst337

hst337 OP

Released 2.1 just now, check out new features and fixes in changelog

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

Other Trending Topics Top

Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement