JKWA
Author of Advanced Functional Programming with Elixir
Trending in Blog Posts
At the heart of every Phoenix application is the often “invisible” HTTP server layer.
For over a decade Cowboy has served the community ...
New
Hey everyone! :waving_hand:
I’ve published Part 7 of the Building Distributed Systems in Elixir series, where we build core distributed ...
New
So, instead of wasting my afternoon arguing with anonymous handles on X, I turned to my trusty, soulless assistant and said: “Listen, ple...
New
New article: Elixir Project Structure — From mix new to a Growing Codebase
I’ve published a new article in my Elixir learning series on d...
New
An educational side project in Elixir, Phoenix, and Tauri. I share what I learned while wiring Automerge into the BEAM, including how I s...
New
The way Phoenix is set up adding a CDN sub-domain for serving static assets, without worrying about the main dynamic content, is incredib...
New
Wrote about how to safely run a globally unique process in an Elixir cluster, and a scary story from the past!
Learn about :global for r...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
I certainly feel like lenses could get a lot more attention on elixir, but does a blogpost in favor of them need to start with dunking on elixirs built in lenses? – especially given most of the critic stated could be mitigated by a single
Enum.map?There’s also reasons why elixir doesn’t allow you to access structs when using bare keys. Structs in elixir are not treated as “data containers”, but as user defined datatypes, which might want to be used as a scalar. If you want that user defined datatype to be accessible like other map data you can implement the Access behaviour, which can then take into account that structs internals. The reason for a behaviour over a protocol is iirc due to performance reasons, potentially even ones of the past, but I’m not sure. You can certainly see how
Accesswants to be a protocol in spirit. Sadly this means this is less likely to be implemented that e.g. anEnumerableespecially for library code.But it’s always possible to access struct keys without
Accessimplemented by forcing map key access usingAccess.keyorAccess.key!, just likeMap.getworks on structs.garrison
As someone unfamiliar with the surrounding theory, I found the framing in terms of Elixir’s stdlib to be pedagogically helpful. Of course the points you make about
Accessare also useful context and could be incorporated.The difference between behavio(u)rs and protocols is that of extensibility, right? So by turning
Accessinto a protocol you are essentially saying that “other people” can decide whether my struct can be accessed like a map. Not just the user themselves, but any third party that invokesdefimplin the user’s dependency tree.Does that actually make semantic sense?
TBH this question may be too theoretical. What’s the canonical example of a struct that should implement
Access?krasenyp
You are correct about protocols. In my experience they’re criminally underused in Elixir and most people have fixation on behaviours for polymorphism but protocols are where it’s at.
JKWA
Elixir’s approach is pragmatic and works well. But when the same path behaves differently depending on the operation (nil vs. create vs. crash), it’s easy to miss encoding an invariant. Lenses just package that consistency into a reusable abstraction.
JKWA
Hmm… You can.. but should? That’s a tough one. I searched Ash and Phoenix for “defimpl Access” and didn’t see any.
JKWA
This Lens does not convert a struct into a map, allowing it to continue to behave as a scalar while exposing a narrowly defined, explicit access path.
lud
Access is not a protocol, you will not find defimpl Access. You should search for “def fetch”!
krasenyp
I finally had some time to go through the article. Knowing lenses from Haskell and being disappointed by the lack of interest in functional programming in the community, it’s a breath of fresh air. Nice introduction and examples. Good job!
JKWA
Thanks!