hissssst / pathex

Fastest tool to access data in Elixir
BSD 2-Clause "Simplified" License
337 stars 17 forks source link

Single-line import of core, lenses, and combinator #26

Open zachallaun opened 1 year ago

zachallaun commented 1 year ago

Pathex is super neat, but the ergonomics are hampered by having to import 2-3 different modules for even relatively simple uses. This example on the forum, for instance: https://elixirforum.com/t/find-a-specific-string-in-an-unstructured-and-nested-list/53918/10?u=zachallaun

I’d propose that use Pathex should be updated to import a much larger set of primitives, including those from combinator, lenses, etc.

zachallaun commented 1 year ago

Alternatively: Lenses and Combinator could become private modules, with their functions being re-exported by the Pathex module. This means the behavior of use Pathex would not need to change and documentation would be consolidated.

zachallaun commented 1 year ago

Updated the title to something that better represents the desired outcome.

hissssst commented 1 year ago

Yeah, I've thought about this and I came up with different approaches for this

  1. Leave it all as it is. It is simple, explicit and it reflects how people use the library. For 90% use cases, you just import Pathex. For 9% of use cases you also import Pathex.Lenses. And only for 1% of use cases import Pathex.Combinator. And even in most cases, one could just call functions from Pathex.Lenses or Pathex.Combinator directly

  2. Move everything to Pathex and suggest using import Pathex. This would add a lot of complex functions with very generic names. Using only option would be even more verbose

  3. Move everything to use Pathex has the same problem as above

  4. use Pathex, lenses: true, combinator: true. Nice, but this saves only a few characters and is less explicit