Algosim documentation: CustomSort

CustomSort

Sorts a container using a custom comparer.

Syntax

Description

If X is any container and c the expression for a comparer in left and right, then CustomSort(X, c) returns X sorted using the comparer defined by c.

To sort a container using a standard comparer, use the sort function instead. To sort a container using the default comparer applied to images of the items under a given function, use the SortBy function instead.

Examples

Alice ≔ ExampleData("Alice in Wonderland");

WordWrap(
  join(
    last(
      CustomSort(
        unique(
          filter(
            words(Alice),
            s ↦ ∀(s, (c ↦ ChrIsLetter(c) ∧ ChrIsLowerCase(c)))
          )
        ),
        CompareValue(#left, #right)
      ),
      20
    )
  )
)
occasionally, difficulties, straightened, explanations, thoughtfully,
thunderstorm, neighbouring, consultation, nevertheless, hippopotamus,
straightening, uncomfortable, circumstances, extraordinary, inquisitively,
uncomfortably, conversations, contemptuously, disappointment, affectionately

Note: In this case, it has been better to use the SortBy function.

See also