marick

marick

A new (sort of) package for traversing nested data structures. Heavy on documentation

TL;DR I’ve forked the Lens package, changed the API some, added new lens makers and – most importantly – added a ton of documentation. In a usable state, but more could be done. Should I? Let me know. lens2 | Hex

——

In functional languages without mutable data structures, this has long been a topic: “how do you deal with the problem of updating one little piece of data deep inside a big nested structure?" Access is the built-in solution.

Another type of solution – popularized originally in Haskell – was “lenses”. The original lens package had lousy documentation, a metaphor that didn’t actually work, and an API that… didn’t encourage readable code. This, for example, is from an introductory explanation.

   Foo <$> f a <*> f b <*> pure c

Alas, because “first mover advantage” is very much a thing in libraries, that particular approach to lenses (including API) spread to other languages.

This has long frustrated me, to the point where (until I gave up on PureScript) I was writing a book called Lenses for the Mere Mortal.

In the dynamic languages, lens-equivalents haven’t been as hard to learn (fewer persnickety types), but I do think they need more explanation than the typical library does. But they tend not to get that.

A while back, I decided I would make documentation pull requests, and even a tutorial, for the Elixir lens package I’ve been using. But I got carried away and made API changes and added lenses for MapSet and BiMap/BiMultiMap (because I’d written them for my own code, and why should people who also wanted to use them with lenses have to repeat that work?) See the Rationale for more, including “Why not use Access?” and “Why a new package?”

The end result was something that is backwards compatible – except for one class of functions – but too different from the original to be merged. So I forked it.

This was a pretty big digression from my main retirement activity. While it’s in a usable state (tutorial, expanded doc strings, working code – almost all of it Paweł Obrok’s original), it could use more work. But I don’t want to do it if no one cares. So, if you’re inclined, take a look and let me know if you care.

Thanks again to Paweł Obrok and also Jean-Philippe Cugnet (for TypedStructLens), whose code made this mostly a matter of documentation.

Most Liked

krishna_vaguelyright

krishna_vaguelyright

I never though this could be a problem. I would love to see codebases & their architectural decisions on how/why they arrived at such deeply nested structures.

Where Next?

Popular in RFCs Top

sleipnir
Hey! Want to contribute to a cool compiler project? Check out the good first issues in the Honey Potion Compiler! Honey Potion is a com...
New
BartOtten
This thread once discussed Routex in it’s early form. It has been repurposed to gather feedback and discusses pre-releases. Currently: p...
New
wingyplus
I just publish a library called redoc_ui_plug | Hex. The library renders Redoc UI from the openapi specification url. I used this library...
New
KristerV
I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases an...
New
miolini
Hi :waving_hand: I’ve been working on CanvasCraft, a 2D drawing library for Elixir built on top of Skia via Rustler. It provides a decla...
New
bluzky
Hi everyone, I would like to introduce my new project OrangeCMS, it’s an application that help you to create/edit content post for your ...
New
alisinabh
Hey everyone :wave: I was recently working on a hobby project that I have deployed on a platform that did not provide quick and easy acc...
New
brettbeatty
At my work we build a lot of mix tasks for backfills and other maintenance tasks. Even with OptionParser we seem to copy a lot of boilerp...
New
pknoth
Built on top of boruta | Hex, I am on the way to creating a standalone OAuth 2.0/OpenID Connect server thinking of a lightweight Keycloak...
New
weakwire
Hello people, Big fan of elixir &amp; phoenix LiveView. While designing LiveView applications I use LiveComponent extensively. Issue-I...
New

Other popular topics Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement