# Function that takes vector of parameterically typed values

**URL:** <https://discourse.julialang.org/t/function-that-takes-vector-of-parameterically-typed-values/60374>\
**Category:** New to Julia\
**Created:** [May 1, 2021, 11:20am UTC](https://discourse.julialang.org/t/function-that-takes-vector-of-parameterically-typed-values/60374 "2021-05-01T11:20:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HiroIshida](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hiroishida/32/7424_2.png) [@HiroIshida](https://discourse.julialang.org/u/HiroIshida)\
**Post date:** [May 1, 2021, 11:20am UTC](https://discourse.julialang.org/t/function-that-takes-vector-of-parameterically-typed-values/60374/1 "2021-05-01T11:20:07Z")

</div>

Let us consider the following types

```julia
abstract type A end
struct A1 <: A end
struct A2 <: A end

struct B{T<:A}
    type::T
end

```

Now what I want to do is write a function as narrowest as possible that accepts both `vec1` and `vec2` below

```julia
b1 = B(A1())
b2 = B(A2())
vec1 = [b1, b1]
vec2 = [b1, b2]

```

My first attempts was defining function like

```julia
sample1(vec::Vector{B}) = ()

```

but it fails to accepts `vec1` because `vec1`’s type is `Vector{B{A1}}` and `Vector{B{A1}} <: Vector{B}` is false. Then, my second attempt was like

```julia
sample2(vec::Vector{B{T}}) where T <: A = ()

```

but this function fails to accept `vec2` as `Vector{B} <: (Vector{B{T}} where T<:A)` is false.

How should I define a function that accepts `vec1` and `vec2`?

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [May 1, 2021, 11:35am UTC](https://discourse.julialang.org/t/function-that-takes-vector-of-parameterically-typed-values/60374/2 "2021-05-01T11:35:49Z")

</div>

Have you tried the following?

```julia
sample(vec::Vector{<:B}) = ()

```

Edit: ~~no, I’m afraid that would not work~~ actually it does work, I don’t know whether this is as narrow as you would like it though.
