Skip to content

Instantly share code, notes, and snippets.

@mbklein
Created December 21, 2023 01:47
Show Gist options
  • Save mbklein/a90a6691a05a203c641fe21b463d24b5 to your computer and use it in GitHub Desktop.
Save mbklein/a90a6691a05a203c641fe21b463d24b5 to your computer and use it in GitHub Desktop.
defmodule DeepSort do
def sort(x) do
case Enumerable.impl_for(x) do
nil ->
x
_ ->
x
|> Enum.map(fn
{k, v} -> {k, sort(v)}
v -> sort(v)
end)
|> Enum.sort_by(fn
{k, _v} -> k
v -> v
end)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment