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

starts(with:by:)

Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test. シーケンスの最初の要素らが別のシーケンスの中の要素らと同等かどうかを、与えられた述部を同等性テストとして使って指し示すブール値を返します。

Declaration 宣言

func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix, by areEquivalent: (Base.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool where PossiblePrefix : Sequence

Parameters パラメータ

possiblePrefix

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 the initial elements of the sequence are equivalent to the elements of possiblePrefix; otherwise, false. If possiblePrefix has no elements, the return value is true. true、もしシーケンスの冒頭の要素がpossiblePrefixの要素と等しいならば;そうでなければfalsepossiblePrefixが1つも要素を持たないならば、戻り値はtrueです。

Discussion 解説

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 possiblePrefix. 計算量:O(m)、ここでmはシーケスの長さとpossiblePrefixの長さのより短い方です。

  • 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である。(推移性)