# Is it a good idea to avoid Channel{Any} and how to avoid it?

**URL:** <https://discourse.julialang.org/t/is-it-a-good-idea-to-avoid-channel-any-and-how-to-avoid-it/30932>\
**Category:** General Usage\
**Created:** [November 10, 2019, 10:06pm UTC](https://discourse.julialang.org/t/is-it-a-good-idea-to-avoid-channel-any-and-how-to-avoid-it/30932 "2019-11-10T22:06:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [November 10, 2019, 10:06pm UTC](https://discourse.julialang.org/t/is-it-a-good-idea-to-avoid-channel-any-and-how-to-avoid-it/30932/1 "2019-11-10T22:06:03Z")

</div>

Hello,

I have the following code

```julia
ljulia> lst_a = [1, 2, 3, 4]
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> lst_b = [10.1, 11.1, 12.1, 13.1]
4-element Array{Float64,1}:
 10.1
 11.1
 12.1
 13.1

julia> function generator()
           Channel() do channel
               for (a, b) in zip(lst_a, lst_b)
                   t = (a=a, b=b)
                   put!(channel, t)
               end
           end
       end
generator (generic function with 1 method)

julia> g = generator()
Channel{Any}(sz_max:0,sz_curr:1)

julia> for t in g
           println(t)
           println(typeof(t))
       end
(a = 1, b = 10.1)
NamedTuple{(:a, :b),Tuple{Int64,Float64}}
(a = 2, b = 11.1)
NamedTuple{(:a, :b),Tuple{Int64,Float64}}
(a = 3, b = 12.1)
NamedTuple{(:a, :b),Tuple{Int64,Float64}}
(a = 4, b = 13.1)
NamedTuple{(:a, :b),Tuple{Int64,Float64}}

julia> g = generator()
Channel{Any}(sz_max:0,sz_curr:1)

julia> collect(g)
4-element Array{Any,1}:
 (a = 1, b = 10.1)
 (a = 2, b = 11.1)
 (a = 3, b = 12.1)
 (a = 4, b = 13.1)

```

`g` is `Channel{Any}(sz_max:0,sz_curr:1)`

I often read that using `Any` is bad because of performance issue in Julia, so I wonder if that’s the case here (I want to mimic a Python `yield`) but I haven’t been able to avoid it.

I tried to do something like

```julia
    Channel{NamedTuple}() do channel
        ...
    end

```

or even more “precise”

```julia
    Channel{NamedTuple{(:a, :b),Tuple{Int64,Float64}}}() do channel
        ...
    end

```

but it doesn’t work.

So… I wonder if it’s a really a good idea to avoid Channel{Any} and how to avoid it?

Kind regards
