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

type1fool
After discussing some of my ideas around Event Sourcing at last night’s Elixir Happy Hour in Austin (highly recommend), I spent some time...
New
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
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
WyvernoDragon
I’ve been working on pgRx: a query engine that uses BEAM lightweight processes instead of PostgreSQL’s fork-per-connection model. The nu...
New
tmbb
I’ve started working on a toy project to compile extended POSIX-compatible regular expressions into NimbleParsec combinators. These combn...
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
felix-starman
I’ve noticed that often when I find myself needing to manually set content-disposition - [MDN] the advice is usually to use URI.encode_ww...
New
Hedgehog-ai
Hello I would like feedback on an experimental neuroevolution (including substrate encoding) library called Bardo based on the amazing wo...
New
weakwire
Hello people, Big fan of elixir &amp; phoenix LiveView. While designing LiveView applications I use LiveComponent extensively. Issue-I...
New
sodapopcan
EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators · GitHub This project is not quite ready for p...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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...
274 41539 114
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
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
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement