Function parameter: `any` or `some`?


I have a function f1 that I would like to use with Array and Set
I have declared the function parameter as any Sequence<Int>


  1. For function parameters, is there any difference between any or some ?
  2. Is one preferred over the other? Why?


let array = [1, 2, 3, 4, 5, 6, 7]
let set = Set([1, 2, 3, 4, 5, 6, 7])

//When a parameter is declared as `any` or `some` - Is there any difference?
func f1(sequence: any Sequence<Int>) {
    sequence.forEach { print($0) }

f1(sequence: array)
f1(sequence: set)
1 Like

If you don't know which one you want, you want some.

These are exactly the same:

func f1(sequence: some Sequence<Int>)

func f1<S>(sequence: S) where S: Sequence, S.Element == Int

but any is different.


Thanks a lot @David_Smith