Equalable, Comparable, Readable - missing kernel protocols

There are a lot of useful protocols which are describing some relations between types. But dispatching of standard elixir protocol is always happening through only one, first given argument. But what if you want to describe some relation between pair of values of some types? And what about N values of some types? I have a couple of examples which allow to define this kind of arity 2 relations:

  1. Simplest one is Equalable which is similar to Eq type class, and which allows to define symmetric equivalence relation for pair of types: https://github.com/timCF/equalable

  2. Next is Comparable which is extended Equalable, similar to Ord type class: https://github.com/coingaming/comparable

  3. And the last example is Readable protocol which is generic version of Read type class: https://github.com/coingaming/readable

All examples have readme files with detailed explanation and examples. At the moment I don’t have good ideas about generalization of these n-arity protocols, they are very custom things now. Maybe you have some ideas or you know some libraries which already implement this generic concept of n-arity protocols. Thanks!

7 Likes