List sorting function help

About Monkey 2 Forums Monkey 2 Programming Help List sorting function help

This topic contains 5 replies, has 3 voices, and was last updated by  Mark Sibly 1 year, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8476

    Hezkore
    Participant

    I need to sort a list containing a custom class.
    The class contains lots of stuff, but I want to sort it by name.
    If the name begins with @ it should be at the very top and + after that.
    (Or would be happen automatically when sorting text?)

    How would I go about doing that in Monkey 2?

    #8478

    Mark Sibly
    Keymaster

    The basic idea is…

    The lambda (or method/function) needs to return the same result as the ‘spaceship’ operator, ie: an int value <0 if x<y; an int value >0 if x>y; or 0 if x=y.

    #8482

    Hezkore
    Participant

    It has to be Lambda:Int though, right? (confused)

    But with that method, the + sign in names would cause users to jump to the top.
    I want names that starts with @ to be first, second should be names that starts with +.
    And all the rest of the names below that.
    That bit confuses me…

    Right now, I’ve just done so that when comparing names, the @ and + are replaced with 1 and 2, only during the sort test.

    #8483

    impixi
    Participant

    You could maybe do something like this:

    [/crayon]
    #8487

    Mark Sibly
    Keymaster

    You’ll need to write a custom comparison routine, something like (untested)…

    #8488

    Mark Sibly
    Keymaster

    It has to be Lambda:Int though, right? (confused)

    Oops, yes.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.