Swapping

  • If the given predicate is true, the given a and b values are swapped in an inout fasion, and true is returned. Otherwise, no swap takes place, and false is returned.

    Declaration

    Swift

    @discardableResult
    public func swap<T>(_ a: inout T, _ b: inout T, if predicate: () -> Bool) -> Bool
  • Undocumented

    Declaration

    Swift

    public func swapped<T, U>(_ a: T, _ b: U) -> (U, T)
  • Declaration

    Swift

    public func swapped<T>(_ a: T, _ b: T, if predicate: () -> Bool) -> (T, T, Bool)

    Return Value

    If the given predicate is true, a tuple of (b, a, true) Otherwise, (a, b, false)