poteat / hkt-toolbelt

✨Functional and composable type utilities

Home Page:http://hkt.code.lol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement `Comparable`, `Sort` methods

MajorLift opened this issue · comments

Currently, we only have comparators for number types. We should implement coherent logic around handling comparable types in general.

  • List.Comparable
    • Given a comparator function F and a list T, return true iff every element of T is comparable using F.
    • (F: Kind, T: Comparable[]) --> Boolean
  • String.Compare
    • Compares two strings by alphabetical order.
    • (A: String, B: String) --> -1 | 0 | 1
  • Object.Compare
    • Compares two objects based on a given comparator.
    • (F: Kind, A: Record, B: Record) --> -1 | 0 | 1
  • List.Sort
    • Given a list T of comparable types, sort the elements using the built-in compare methods and return the result.
    • (T: Comparable[]) --> ?[]
  • List.SortOn
    • Given a comparator function F and a list T of comparable types, sort the elements using the user-supplied comparator and return the result.
    • (F: Kind, T: ?[]) --> ?[]
  • List.Max
    • Given a comparator function F and a list T of comparable types, return the maximum.
    • (F: Kind, T: Comparable[]) --> Comparable
  • List.Min
    • Given a comparator function F and a list T of comparable types, return the minimum.
    • (F: Kind, T: Comparable[]) --> Comparable

The implementation should include unit tests and JSDoc comments that adhere to the guidelines established in the style-guide/ directory.