How to do dynamic dispatch?

As far as I know, the compiler will statically resolve to the overload with the best-matching signature. And that is T: Collection in your case.

A simple example

func foo<T: RandomAccessCollection>(_ arg: T) { print("RandomAccessCollection") }

func foo<T: Collection>(_ arg: T) { print("Collection") }

func doo<T: Collection>(_ arg: T) {
  foo(arg)
}

doo([1, 2, 3])
doo("44444444")

foo("44444444")
foo([1, 2, 3])

// Collection
// Collection
// Collection
// RandomAccessCollection

Here's a very similar case, by the way:

2 Likes