<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/JoinedSequence/lexicographicallyPrecedes(_:by:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:STsE25lexicographicallyPrecedes_2bySbqd___Sb7ElementQz_ADtKXEtKSTRd__ACQyd__ADRSlF::SYNTHESIZED::s:s14JoinedSequenceV"
  },
  "title" : "lexicographicallyPrecedes(_:by:)"
}
-->

# lexicographicallyPrecedes(_:by:)

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the given
predicate to compare elements.

```
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence, by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
```

## Parameters

`other`

A sequence to compare to this sequence.

`areInIncreasingOrder`

A predicate that returns `true` if its first
argument should be ordered before its second argument; otherwise,
`false`.

## Return Value

`true` if this sequence precedes `other` in a dictionary
ordering as ordered by `areInIncreasingOrder`; otherwise, `false`.

## Discussion

The predicate must be a *strict weak ordering* over the elements. That
is, for any elements `a`, `b`, and `c`, the following conditions must
hold:

- `areInIncreasingOrder(a, a)` is always `false`. (Irreflexivity)
- If `areInIncreasingOrder(a, b)` and `areInIncreasingOrder(b, c)` are
  both `true`, then `areInIncreasingOrder(a, c)` is also
  `true`. (Transitive comparability)
- Two elements are *incomparable* if neither is ordered before the other
  according to the predicate. If `a` and `b` are incomparable, and `b`
  and `c` are incomparable, then `a` and `c` are also incomparable.
  (Transitive incomparability)

> Note: This method implements the mathematical notion of lexicographical
> ordering, which has no connection to Unicode.  If you are sorting
> strings to present to the end user, use `String` APIs that perform
> localized comparison instead.

> Complexity: O(*m*), where *m* is the lesser of the length of the
> sequence and the length of `other`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)