# foo(T) where T # in Vector{DataType}

**URL:** <https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243>\
**Category:** General Usage\
**Created:** [August 28, 2021, 7:37pm UTC](https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243 "2021-08-28T19:37:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [August 28, 2021, 7:37pm UTC](https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243/1 "2021-08-28T19:37:31Z")

</div>

Hellow, how can i write a function like this:

```julia
vector_data_type = [
  Int64,
  Int32,
  Int16,
]

foo(T) where T # in vector_data_type

```

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 28, 2021, 7:46pm UTC](https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243/2 "2021-08-28T19:46:08Z")

</div>

With a for loop and `@eval`:

```julia
julia> for T in (Int64, Int32, Int16)
           @eval foo(::$T) = string($T)
       end

julia> foo(1)
"Int64"

julia> foo(Int16(1))
"Int16"

```

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 28, 2021, 7:49pm UTC](https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243/3 "2021-08-28T19:49:46Z")

</div>

Or perhaps you meant a case where the source is the same for all the methods and doesn’t requires any interpolation/eval. You can use a Union for many cases like that.

```julia
julia> bar(::T) where T <: Union{Int64, Int32, Int16} = string(T)
bar (generic function with 1 method)

julia> bar(1)
"Int64"

julia> bar(Int16(1))
"Int16"

julia> bar(Int8(1))
ERROR: MethodError: no method matching bar(::Int8)

```

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 28, 2021, 7:49pm UTC](https://discourse.julialang.org/t/foo-t-where-t-in-vector-datatype/67243/4 "2021-08-28T19:49:46Z")

</div>

You mean to define such a function?

```julia
foo(::Type{T}) where T<:Union{Int64,Int32,Int16}

```

but I would guess you’re actually looking for `Integer` (which is a supertype of all of those, but may also encapsulate other integer types)
