Order

interface Order<in Element> : KoneContext(source)

Describes a context that provides linear (total) order as a compareTo.

Such contexts are used instead of usual compareTo operator defined right inside the Element type for several reasons. Some of them are:

  • Following structural pattern, any behaviour between elements should not be a part of the elements' logic but a part of assumed context. (For example, summing two integers together, we assume that we are summing them as two integer, but not as a residue of some modulo.)

  • Such separation of entities and operations over them brings modularity: you can change operations context leaving the entities the same.

Type Parameters

Element

The type of elements for which this order context is defined.

Types

Link copied to clipboard
object Companion

Companion object for Order interface providing factory methods and constants for creating Order instances.

Properties

Link copied to clipboard

Returns an Order context for elements wrapped in Maybe where None is considered the greatest value.

Link copied to clipboard

Returns an Order context for elements wrapped in Maybe where None is considered the least value.

Link copied to clipboard

Returns an Order context for nullable elements where null is considered the greatest value.

Link copied to clipboard

Returns an Order context for nullable elements where null is considered the least value.

Functions

Link copied to clipboard

Converts provided Order receiver into Comparator that delegates its Comparator.compare operator to Order.compareTo operator.

Link copied to clipboard
abstract infix fun Element.compareWith(other: Element): ComparisonResult

Compares this and other elements.