Function parameter: `any` or `some`?

Overview

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>

Questions

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

Code

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)
2 Likes

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.

4 Likes

Thanks a lot @David_Smith