Thought this would be a nice way to start the year - have you seen or written an Erlang or BEAM language function or piece of code that you are particularly fond of? Perhaps you admired its simplicity (or complexity!) or maybe your surprised yourself or surpassed your own expectations of what is possible?
Whatever the reason, please share!
(If sharing code that is not in Erlang, please state which BEAM language it is)
I have recently written a bit of code for ReVault:
This isn’t particularly fancy or impressive code (and the module at large is full of TODOs), but I was real glad to be able to use maybe expressions in my own projects in a way that simplified the validation workflow a bunch.
The long time and lot of community work behind getting that feature into the language is part of the feeling, of course.
The config data structure is a TOML tree, stored in a persistent_term. Those few lines of code are all I need to traverse the tree by a path and get the desired subtree or final leaf. Love the simplicity
Here’s a little binary log parser that I made a long time ago. I often refer to it when telling other people about how powerful the binary notation (and pattern matching) is in Erlang. I mostly love just how compact and readable it is.
It’s not exactly complicated to understand but for me the way Joe takes this simple function in his post sells it for me And using this simple function, you can introduce people to some concepts of Erlang but also to change the way some people think about processes and Erlang systems as a whole: Joe wrote this post about Erlang / Elixir web servers where he said that “We do not have ONE web-server handling 2 millions sessions. We have 2 million webservers handling one session each.”. That is what really made processes click for me