# Any way to make this one-liner type stable?

**URL:** <https://discourse.julialang.org/t/any-way-to-make-this-one-liner-type-stable/10636>\
**Category:** General Usage\
**Created:** [May 1, 2018, 1:27pm UTC](https://discourse.julialang.org/t/any-way-to-make-this-one-liner-type-stable/10636 "2018-05-01T13:27:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [May 1, 2018, 1:27pm UTC](https://discourse.julialang.org/t/any-way-to-make-this-one-liner-type-stable/10636/1 "2018-05-01T13:27:42Z")

</div>

I’ve got this function which widens each of the arguments of a `Tuple` type

```julia
widen_tupleargs(::Type{T}) where {T<:Tuple} = Tuple{map(widen,T.parameters)...}

```

e.g.

```julia
julia> widen_tupleargs(Tuple{Int16,Float16})
Tuple{Int32,Float32}

```

However, its not type-stable,

```julia
julia> @code_warntype widen_tupleargs(Tuple{Int16,Float16})
Variables:
  #self# <optimized out>
  #unused# <optimized out>

Body:
  begin 
      return (Core._apply)(Core.apply_type, (Core.tuple)(Main.Tuple)::Tuple{DataType}, $(Expr(:invoke, MethodInstance for map(::Base.#widen, ::SimpleVector), :(Main.map), :(Main.widen), :((Core.getfield)($(Expr(:static_parameter, 1)), :parameters)::SimpleVector))))::Any
  end::Any

```

Is there any way to write this so that it is type stable? I’d be curious on either 0.6 or 0.7 (above output was 0.6). Thanks for any help!

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [May 1, 2018, 1:36pm UTC](https://discourse.julialang.org/t/any-way-to-make-this-one-liner-type-stable/10636/2 "2018-05-01T13:36:05Z")

</div>

You could try something like this, with `head` and `tail` (the versions for tuple type):

```julia
widen_tupleargs(::Type{Tuple{}}) = Tuple{}
widen_tupleargs(::Type{T}) where {T<:Tuple} = Base.tuple_type_cons(widen(Base.tuple_type_head(T)), widen_tupleargs(Base.tuple_type_tail(T)))

```

This is for Julia 0.6, I didn’t check if it changed in 0.7

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [May 1, 2018, 1:40pm UTC](https://discourse.julialang.org/t/any-way-to-make-this-one-liner-type-stable/10636/3 "2018-05-01T13:40:42Z")

</div>

Awesome, `Base.tuple_type_head/tail` is exactly what I was looking for, thanks! I just checked on 0.7 and it works exactly the same.
