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

BartOtten
This lib is now published and has a new topic. Once this topic was about PhxAltRoutes. A lib pioneering localized routes for Phoenix. I...
New
wingyplus
Hi, I start working on the fork version of Elixir GRPC. What I’ve done is the past few days: Support Elixir 1.11+ Support OTP 23+ OTP...
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
pzingg
https://github.com/pzingg/phx_cookie_consent I took a phx.gen.auth application and added support for storing a user’s cookie consent set...
New
manuel-rubio
There was some time when I started thinking about giving a boost to Lambdapad, the initiative from @garretsmith in Erlang that I loved wa...
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
dimamik
Hi! I’ve been working with Pipecat in Python for quite a while now, and while it’s effortless to set up, when building AI voice agents at...
New
Overbryd
Polyglot-Ex Rust and wasmex bindings for polyglot. State: Pre-release Hi there, I am starting a thread for my humble bindings library ...
New
simulacre7
Hi everyone, I’m building Aethrion, an early alpha Elixir runtime for persistent AI characters. Repo: GitHub - simulacre7/aethrion: A s...
New
andreashasse
Hi all, I’ve been working on PhoenixSpectral, a library that makes Phoenix controller @spec annotations drive both OpenAPI generation an...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement