As noted in my last post, before tagging a new release of the Algorithms package I'd like to have a bit of discussion about naming of some of the new additions. In this thread I'd like to invite comments about the
sortedPrefix(_:) method, which you can read about in the Sorted Prefix guide.
This method has been challenging to name! It is related to (or at least sounds related to), but is not the same as:
- a sorted version of the prefix, e.g.
partialSortfrom C++, which operates in-place and leaves the rest of the collection in indeterminate order.
min()method that already exists on sequences, which returns the smallest element — but if we were to call this
min(_ count: Int), then would we also need a
max(_ count: Int)?
- "prefix orders", the set theory term
These are the names that were discussed during the addition process:
_ = numbers.sortedPrefix(5) _ = numbers.smallest(5) _ = numbers.partiallySorted(5) _ = numbers.sort(upTo:5) _ = numbers.sortFirst(5) _ = numbers.min(5)
I'm sold on
sortedPrefix(_:) as the best name of those proposed so far, since it's essentially a more efficient version of
sorted().prefix(_:). I'd love to hear peoples' thoughts and other suggestions of names that we haven't come across yet.