Equality

interface Equality<in Element> : KoneContext(source)

Describes a context that provides equality equivalence relation on the set of elements of type Element (or some subdomain). The relation is described by equalsTo function.

Such contexts are used instead of usual equals overloading 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 equality context is defined.

Types

Link copied to clipboard
object Companion

Companion object for Equality interface providing factory methods for creating Equality instances.

Properties

Link copied to clipboard

Returns an Equality context for nullable elements based on this non-nullable equality context.

Functions

Link copied to clipboard
open infix fun Element.equalsTo(other: Element): Boolean

Checks equality of this and other elements.