Yes
proc inside(x: int, y: openArray[int]): bool =
x in y
echo 1.inside([1,2,3,4,5])
No
import sets
proc inside(x: int, y: openArray[int] | HashSet[int]): bool =
x in y
echo 1.inside([1,2,3,4,5])
Error: type mismatch: got <int literal(1), array[0..4, int]>
but expected one of:
proc inside(x: int; y: openArray[int] | HashSet[int]): bool
first type mismatch at position: 2
required type for y: openArray[int] or HashSet[system.int]
but expression '[1, 2, 3, 4, 5]' is of type: array[0..4, int]
expression: inside(1, [1, 2, 3, 4, 5])
Openarray is a special type (this will probably change in the future), when you put it in a union type then you're trying to treat it like a typeclass which it is not, it has to be concrete so types like seq and array can convert to it. You should separate it into overloads like this:
import sets
proc inside(x: int, y: openArray[int]): bool =
x in y
proc inside(x: int, y: HashSet[int]): bool =
x in y
Note that these 2 are equivalent (implicit generics)
proc inside(x: int, y: openArray[int] | HashSet[int]): bool =
x in y
proc inside[T: openArray[int] | HashSet[int]](x: int, y: T): bool =
x in y