Generic Instance Method 総称体インスタンスメソッド

elementsEqual(_:by:)

Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test. このシーケンスともう一方のシーケンスが同等の要素を同じ順序で含むかどうかを、与えられた述部を同等テストとして使って、指し示しているブール値を返します。

Declaration 宣言

func elementsEqual<OtherSequence>(_ other: OtherSequence, by areEquivalent: (Base.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence

Parameters パラメータ

other

A sequence to compare to this sequence. あるシーケンス、このシーケンスと比べることになります。

areEquivalent

A predicate that returns true if its two arguments are equivalent; otherwise, false. ある述部、それはそれの2つの引数が等しいならばtrueを返します;そうでなければ、false

Return Value 戻り値

true if this sequence and other contain equivalent items, using areEquivalent as the equivalence test; otherwise, false. true、このシーケンスとotherareEquivalentを同等性テストとして使って同じ要素らを含むならば;そうでなければ、false

Discussion 解説

At least one of the sequences must be finite. 少なくともシーケンスのうちの一方は有限でなければなりません。

The predicate must be a equivalence relation over the elements. That is, for any elements a, b, and c, the following conditions must hold: 述部は要素に対して同値関係でなければなりません。すなわち、何らかの要素ab、そしてcに対して、以下の条件が保持されなければなりません:

Complexity: O(m), where m is the lesser of the length of the sequence and the length of other. 計算量:O(m)、ここでmはシーケンスの長さとotherの長さのより短い方です。

  • areEquivalent(a, a) is always true. (Reflexivity) areEquivalent(a, a)は常にtrueである。(反射性)

  • areEquivalent(a, b) implies areEquivalent(b, a). (Symmetry) areEquivalent(a, b)areEquivalent(b, a)を意味する。(対称性)

  • If areEquivalent(a, b) and areEquivalent(b, c) are both true, then areEquivalent(a, c) is also true. (Transitivity) areEquivalent(a, b)areEquivalent(b, c)が両方ともtrueならば、そのときareEquivalent(a, c)もまたtrueである。(推移性)