Answers whether both values are equal.
Selfthe value to compare withReturns true when the values are equal.
The six protocols of the standard library: what each one requires, what it provides, and who conforms.
Taught on: Protocols.
Anything that can be compared for equality.
Requires
Answers whether both values are equal.
Selfthe value to compare withReturns true when the values are equal.
Provides
Answers whether the values differ.
Selfthe value to compare withReturns true when the values differ.
Every choice has is and isNot without declaring Equatable. Two of its values are equal when they are the same case with equal payloads.
Conforming Algebraic, Boolean, Dictionary where KeyType is Equatable, ValueType is Equatable, HttpMethod, Redirects, HttpFailure, Division, Integer, SortOrder, List where ItemType is Equatable, Number, Optional where ItemType is Equatable, Ordering, NumberFormat, Rounding, SignStyle, Rational, Record, Result where ValueType is Equatable, FailureType is Equatable, Side, CaseSensitivity, NormalizationForm, String, Stream, Transcendental
Required by Dictionary.of(_:), Dictionary.of(_:valuedBy:), Dictionary::is(_:), Dictionary::hasKey(_:), Dictionary::hasValue(_:), Dictionary::value(at:), Dictionary::value(at:defaultingTo:), Dictionary::set(_:to:), Dictionary::update(at:with:), Dictionary::update(at:defaultingTo:with:), Dictionary::remove(at:), Dictionary::remove(atEvery:), Dictionary::merge(with:), Dictionary::merge(with:choosing:), GroupedList::group(on:), GroupedList::tally(), GroupedList::index(on:), GroupedNonEmptyList::group(on:), GroupedNonEmptyList::tally(), GroupedNonEmptyList::index(on:), List::is(_:), List::contains(_:), List::contains(everyItemOf:), List::doesNotContain(_:), List::hasDuplicates(), List::hasDuplicates(on:), List::starts(with:), List::doesNotStart(with:), List::ends(with:), List::doesNotEnd(with:), List::firstIndex(of:), List::firstIndex(of:defaultingTo:), List::lastIndex(of:), List::lastIndex(of:defaultingTo:), List::everyIndex(of:), List::removeEvery(_:), List::removeEvery(contentsOf:), List::everyItem(alsoIn:), List::count(of:), List::split(on:), List::removeDuplicates(), List::removeDuplicates(on:), NonEmptyList::removeDuplicates(), NonEmptyList::removeDuplicates(on:), Optional::is(_:), Optional::isNot(_:), Result::is(_:), Result::isNot(_:)
Anything that can represent itself as a String.
Requires
Answers the value as a String.
Returns the String representation of the value.
A choice whose cases carry no payload prints its case name once a namespace declares is Printable for it. The namespace body can stay empty: namespace Side for Side is Equatable, is Printable {}.
An interpolation hole in a String needs a Printable value. Any other value is interpolation-not-printable.
Conforming Algebraic, Boolean, Dictionary where KeyType is Printable, ValueType is Printable, HttpMethod, Redirects, HttpFailure, Division, Integer, SortOrder, List where ItemType is Printable, Number, Optional where ItemType is Printable, Ordering, NumberFormat, Rounding, SignStyle, Rational, Record, Result where ValueType is Printable, FailureType is Printable, Side, CaseSensitivity, NormalizationForm, String, Stream, Transcendental
Required by Dictionary::toString(), List::toString(), List::join(with:), Optional::toString(), Result::toString(), Terminal.print(_:to:)
Anything with a total order among its values.
Requires
Orders the value against another one of the same Type.
Selfthe value to compare withReturns Ordering#Less, Ordering#Equal or Ordering#Greater.
Provides
Answers whether the value is strictly below another.
Selfthe value to compare withReturns true when the value is below the given one.
Answers whether the value is below another, or equal to it.
Selfthe value to compare withReturns true when the value is below the given one or equal to it.
Answers whether the value is strictly above another.
Selfthe value to compare withReturns true when the value is above the given one.
Answers whether the value is above another, or equal to it.
Selfthe value to compare withReturns true when the value is above the given one or equal to it.
Conforming Algebraic (through Orderable), Boolean, Integer (through Orderable), List where ItemType is Comparable, Number (through Orderable), Rational (through Orderable), String
Required by Dictionary::sort(in:), Dictionary::sort(on:in:), NonEmptyDictionary::sort(in:), NonEmptyDictionary::sort(on:in:), List::compare(to:), List::isSorted(in:), List::sort(in:), List::sort(on:in:), List::lowestItem(on:), List::lowestItem(on:defaultingTo:), List::lowestItem(), List::lowestItem(defaultingTo:), List::highestItem(on:), List::highestItem(on:defaultingTo:), List::highestItem(), List::highestItem(defaultingTo:), NonEmptyList::sort(in:), NonEmptyList::sort(on:in:), NonEmptyList::lowestItem(on:), NonEmptyList::lowestItem(), NonEmptyList::highestItem(on:), NonEmptyList::highestItem()
Anything on a line, where a value can be between two others or pulled into a range.
Extends Comparable: a type that conforms to Orderable conforms to it too, and gets what it provides.
Provides
Answers whether the value lies between the two given ones, both included.
The two bounds name the same range in either order: 7::isBetween(10, and 1) is true, and 15::isBetween(10, and 1) is false.
Selfone bound of the range, includedSelfthe other bound of the range, includedReturns true when the value is within the bounds.
Answers the value, pulled into the given bounds.
The answer is the lower bound when the value is below it. It is the upper bound when the value is above it, and the value itself otherwise. The two bounds name the same range in either order: 7::clamp(between 10, and 1) is 7, and 15::clamp(between 10, and 1) is 10.
Selfone bound of the rangeSelfthe other bound of the rangeReturns the clamped value.
Conforming Algebraic, Integer, Number, Rational
Anything whose values can be listed, from a Choice whose Cases carry no payload.
Requires
Answers every value of the Type.
The values stand in the order the Cases are declared in. A Choice has at least one Case, so the answer certainly holds one.
Returns every Case of the Choice, in declaration order.
Every choice whose cases carry no payload has the static cases() without declaring Enumerable. It returns the cases in the order they are declared: Side.cases() is [Start, End, BothEnds].
Derived for Division, NumberFormat, Rounding, SignStyle, Side, CaseSensitivity, NormalizationForm, SortOrder, Ordering, Stream, HttpMethod, Redirects
Anything a property test can build values of.
A Namespace that declares this conformance replaces the generator a property test derives from the Type. The derived generator also makes a failing value smaller, and a conformance answers shrink for that instead. The provided shrink answers no candidates, so a Namespace that writes none of its own has its counterexamples reported as they were drawn.
Requires
Answers a value of the conforming Type, built from a source of randomness.
A property test derives a generator from the Type where a Namespace declares no conformance. Declaring one replaces that generator, for a Type whose values carry an invariant the derived one can not know about.
Randomnessthe source to draw from.Returns a value of the conforming Type.
Provides shrink, with its own entry below.
No namespace in the standard library conforms to it.
provided by Generatable
Answers the smaller values a failing one can be reported as.
A property test that fails asks its counterexample for these candidates, and reports the first one that fails as well. It asks that value for its own, so a body answering one step smaller each time reports the smallest value the property fails on. The runner tries the candidates in the order the List holds them, and skips one that is the failing value itself. The body here answers no candidates, so a Namespace that writes none of its own reports the value the source drew.
Returns the smaller values, smallest first.