Summary: Two suggestions for std.algorithm.schwartzSort()
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from 2010-09-21 12:58:38 PDT ---
Both my experience with Python and some practice with D v2 shows me that in
script-like programs schwartzSort() is useful very often. Python 3 has even
removed the "cmp" argument for its built-in sort, so it always performs a
Schwartz sorting using the "key" argument, because it's simpler to use.

This an usage example of schwartzSort usage, to sort an array of arrays
according to the second item in the sub-arrays:

import std.algorithm;
void main() {
    auto arr = [[5,9],[5,3],[4,12],[7,8],[12,2],[5,8]];
    schwartzSort!((e){ return e[1]; })(arr);
    assert(arr == [[12,2],[5,3],[7,8],[5,8],[5,9],[4,12]]);

To improve the usage of schwartzSort a support for transform function expressed
as string may be added.

For non-English speaking programmers the spelling of schwartzSort is not easy,
and a so commonly used function may enjoy a shorter name any way, so a
"keySort" name may be better ("key" refers to the key argument function of the
Python sort, that's named "transform" in Phobos):

import std.algorithm;
void main() {
    auto arr = [[5,9],[5,3],[4,12],[7,8],[12,2],[5,8]];
    assert(arr == [[12,2],[5,3],[7,8],[5,8],[5,9],[4,12]]);

To help the understanding of this "keySort" name, in the signature of keySort
the "transform" argument may be renamed "key".

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to