Aside the facts that structural types do not conform to protocols yet and there is no existential for tuples like AnyTuple
, I think we might want to create view into a tuple which is indexible.
Bikeshedding:
func == <Tuple>(lhs: Tuple, rhs: Tuple) -> Bool where Tuple : AnyTuple & Equatable {
// Creates something like `TupleSlice<Tuple>`
let (lhsView, rhsView) = (lhs.view, rhs.view)
// indecies must match
guard lhsView.indices == rhsView.indices else { return false }
// on last index it's `() == ()` which is always true
if lhsView.startIndex == lhsView.endIndex, rhsView.startIndex == rhsView.endIndex {
return true
}
// extract first values and compare them (both return a value wrapped into an optional)
guard lhsView.first == rhsView.first else { return false }
// recursion
return lhsView[lhsView.index(after: lhsView.startIndex)...] == rhsView[rhsView.index(after: rhsView.startIndex)...]
}
Or we can simply iterate the indexible views, which should be even faster.