It certainly is contrived -- perhaps knowing more would help illuminate the best approach (or another one I haven't considered?).
I'm implementing a recursive divide-and-conquer algorithm for counting the inversions in an array -- the base cases are when the input has been subdivided such that the array has only one element (or in the case of an odd-length input, zero elements). In either case, there can be no inversions, so that is returned with no additional work. However, in order to take advantage of merge-sort to detect the split inversions (those inversion pairs that have an element on each side of the divided input), I need to return the array in addition to the inversion count. So my first two function clause definitions are as such:
defp sort_and_count([]), do: {[], 0}
defp sort_and_count(list = [_head]), do: {list, 0}
But now that I'm not explicitly matching the empty tail, perhaps I should just return a new list with the single element rather than match the full list and the individual element instead:
defp sort_and_count([]), do: {[], 0}
defp sort_and_count([head]), do: {[head], 0}
Thanks for your insight!
Britt