OrderInvariantCompare v1.0.0 OrderInvariantCompare View Source
OrderInvariantCompare defines the <~>
operator which is used to compare two
items for equality. If they are lists, then it returns true if those lists
contain the same elements, even if those elements are not in the same order.
This can be useful for when you need to test collections of elements which are generated in some random manner.
This module implements the <~>
operator, which is by default unused by
elixir. If another module also implements this function, you can also use the
equal?/2
function which behaves exactly the same.
Link to this section Summary
Functions
Returns true if the values on the left and right are equal. If the values are lists, then this function also returns true if the lists contain the exact same elements, but in a different order
Returns true if the two values are equal. If the values are lists, then this function also returns true if the lists contain the exact same elements, but in a different order
Link to this section Functions
Returns true if the values on the left and right are equal. If the values are lists, then this function also returns true if the lists contain the exact same elements, but in a different order.
Examples
iex> [1, 2, 3] == [3, 2, 1]
false
iex> [1, 2, 3] <~> [3, 2, 1]
true
Returns true if the two values are equal. If the values are lists, then this function also returns true if the lists contain the exact same elements, but in a different order.
Examples
iex> OrderInvariantCompare.equal?([1, 2, 3], [3, 2, 1])
true
This function is identical to the <~>/2
function.