JKWA
Author of Advanced Functional Programming with Elixir
There are many ways to solve equality: duck typing, injection, protocol dispatch.
Here’s why Funx uses the one it does:
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 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lucas-stellet
Hey @JKWA,
First of all, thanks for your book.
I bought it recently and it’s been an enjoyable journey reading it.
I read your article and ran the LiveBook, and I liked your idea so much that I decided to create my own version of your implementation.
The main difference is that I created a separate module for the
Protocoland useddefdelegateto route the function depending on the arity.I would like to your opinion about it.
Thanks!
JKWA
Sure, here’s my take.
From a functional point of view, I think of the protocol as the abstraction itself, defining what it means to be equal. I use
Eq.Utilsas a convenient place to keep helper functions that work withEq.I had considered naming
EqasEq.Protocol, but in the end I leaned away from that. I felt that framing treated the protocol more like an interface for modules to implement, which doesn’t quite match how I think about the abstraction.The combination of
defdelegate eq?(a, b), to: Eq.Protocolandeq?(a, b, comparator)is behaviorally equivalent to my approach, but to me it reads a bit like OOP. Nothing wrong with that, just a different frame.But those are really just semantics, the real difference is in how we handle the third argument. You’re passing a function, while I’m passing a map with an
:eq?key that holds the function. Treating the comparison logic as data makes it easier to compose later. For instance, check out the Funx monoid.JKWA
You might find AI Tutor for Functional Programming - Funx , interesting. Feed in your example and get Claude to focus on the different
eq?/3functions. If it is attending to the usage rules, it does a pretty good job of explaining why you might choose one over the other.