I want to work with a variety of data structures (arrays, singly/doubly linked lists, sorted structures, etc.) on a plug-and-play basis. For example, I want to be able to easily swap in and out the sorted list and the array (which is re-sorted after every insertion/deletion), to test which one has better performance.
In every language I know of, the public interface to such data structures is very inconsistent. So changing the implementation requires a lot of work.
Is there a language, or a language-agnostic design pattern, that makes it easy to define a generic public interface that works with any data structure?
Of course, I understand how different performance would be (e.g., binary search in a sorted array vs linear search in a regular array). All I ask is that the performance of the data structure doesn't degrade asymptotically or by a large constant factor due to the use of the standard interface.
Example problem: iterate through the container of numbers, find the two numbers that are nearest each other, and remove the pair of them. (If several pairs are equal distance, pick an arbitrary pair).
I'd like the code to solve the problem to be unchanged as I switch in and out different containers.