-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't save order and eq in the data structure? #15
Comments
Also see #9 for a potential simplification of such a protocol. |
I don't understand what such a protocol would look like. Can you give an example? |
I believe for example like this: defprotocol Compare do
@spec compare(t, t) :: :eq | :lt | :gt
def compare(lhs, rhs)
end
defimpl Compare, for: Integer do
def compare(lhs, rhs) when is_integer(lhs) and is_integer(rhs) do
cond do
lhs > rhs -> :gt
lhs == rhs -> :eq
lhs < rhs -> :lt
end
end
end
test "compare works on integers" do
assert Compare.compare(2, 3) = :lt
end Any data type that |
I don't see how this simplifies serializing a closed interval over how it is currently done. To serialize a closed interval, the |
If we would use the protocol, we could directly use e.g. |
But you will have to pass the order and eq functions around all the time as well when using the API of If your use-case is to enable |
I am not convinced that this suggestion improves upon the existing API. Maybe we need a PR to investigate the idea further. I think a Protocol will not be needed, but we could attempt to pull out the functions and force the user to always provide the functions when calling any API function. |
When one would like to serialize a
ClosedIntervals
to the disk and/or via JSON, it's problematic to have the functionsorder
andeq
as part of the data structure. Maybe it's better to define a protocol and dispatch it on the data contained in the tree?The text was updated successfully, but these errors were encountered: