The Order typeclass abstracts the ability to compare two instances of any object and determine their total order. Depending on your needs, this comparison can be structural (the content of the object), referential (the memory address of the object), based on an identity (like an Id field), or any combination of these.

It can be considered the typeclass equivalent of Java’s Comparable.

Main Combinators


fun F.compare(b: F): Int

Compare [a] with [b]. Returns an Int whose sign is:

  • negative if x < y
  • zero if x = y
  • positive if x > y
import arrow.*
import arrow.typeclasses.*
import arrow.core.extensions.*

Int.order().run { 1.compare(2) }
// -1

Additionally, Order overloads operators >, <, <=, and >=, following the Kotlin compareTo convention for every type where an Order instance exists.

Int.order().run { 1 > 2 }
// false

F#lte / F#lt

Lesser than or equal to defines total order in a set, it compares two elements, and returns true if they’re equal or the first is lesser than the second. It is the opposite of gte.

Int.order().run {
// true

F#gte / F#gt

Greater than or equal compares two elements and returns true if they’re equal or the first is lesser than the second. It is the opposite of lte.

Int.order().run {
// false

F#max / F#min

Compares two elements and respectively returns the maximum or minimum in respect to their order.

Int.order().run {
// 1
Int.order().run {
// 2


Sorts the elements in a Tuple2.

Int.order().run {
// (2, 1)


Arrow provides OrderLaws in the form of test cases for internal verification of lawful instances and third party apps creating their own Order instances.

Creating your own Order instances

Order has a constructor to create an Order instance from a compare function (F, F) -> Int.

Order { a: Int, b: Int -> b - a }.run {
// false

See Deriving and creating custom typeclass to provide your own Order instances for custom datatypes.

Data types

Module Data types

Type Class Hierarchy

Do you like Arrow?

Arrow Org