
Jean-Philippe Bernardy wrote:
-- The 'isSingleton' method seems unnecessary. Are singleton collections interesting enough to supply a special test for them?
This is based on Christan Maeder idea. We are planning to move to AVL trees for A. Hey, which do not provide a O(1) size function. A singleton test thus becomes valuable, and since costs next to nothing to add to the class I decided to to it.
Here's a more general suggestion: move the method 'front' up into class 'Collection'. It is always meaningful in some way: it would get the leftmost item from a sequence, the least key from a set, the least priority from a priority queue and so on. Sure, the naming is not the most fortunate. What would be appropriate for a method that extracts a somewhat unspecified element? 'split', 'extract', 'view', 'decompose', 'item' or something else? Alternatively, 'front' could be left where it is, extracting the leftmost element. A similar method, which extracts an unspecified element, should be added to 'Collection'. Once you have 'front' you can implement 'isSingleton' and 'null' outside the class. The same is true for 'fold' and a strict 'foldl' which is currently missing. Udo. -- "Being abstract is something profoundly different from being vague." -- E. W. Dijkstra