Re: [elixir-core:11172] A More Human DateTime Comparison API

2022-11-01 Thread José Valim
Unfortunately general comparison requires multiple dispatch, because it is supposed to work regardless of the argument order. For example, imagine that we provide a Comparable protocol and we implement it in Elixir for Integer and Float. Now, the Decimal library will also implement Comparable, and

Re: [elixir-core:11172] A More Human DateTime Comparison API

2022-11-01 Thread Cliff
Okay, I'm totally in love with this idea :) *iex(1)>* *defprotocol Comparable do @spec compare(t, t) :: :lt | :eq | :gt def compare(a, b)enddefimpl Comparable, for: Integer do def compare(a, b) do cond do a < b -> :lt a == b -> :eq a > b -> :gt