How to implement complexed custom sort?

With Orderable protocol you also can use AVLTree like this:

AVLTree.new(fn a, b -> Orderable.orderable(a) < Orderable.orderable(b))

All inserted elements will be automatically sorted.