# Type stability when arguments are functions

**URL:** <https://discourse.julialang.org/t/type-stability-when-arguments-are-functions/4734>\
**Category:** General Usage\
**Created:** [July 8, 2017, 12:16am UTC](https://discourse.julialang.org/t/type-stability-when-arguments-are-functions/4734 "2017-07-08T00:16:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [July 8, 2017, 11:14am UTC](https://discourse.julialang.org/t/type-stability-when-arguments-are-functions/4734/4 "2017-07-08T11:14:08Z")

</div>

Try “lispy tuple recursion,”

```julia
@inline g2(fs::Tuple{Function, Vararg{Function}}, x::Float64) = _g2(0.0, fs, x)
# _gs is a "private" method that processes the first call, then discards that function and recursively calls itself 
@inline _g2(a, fs::Tuple{Function, Vararg{Function}}, x::Float64) = _g2(a + fs[1](x), Base.tail(fs), x)
# But we have to terminate the recursion. This method is called when we've "used up" all the functions
_g2(a, ::Tuple{}, x::Float64) = a

@code_warntype g2((sin, cos, tan), 3.14)

```

You’ll see this is type-stable even without any of the type-assertions/declarations.

---

_[View the full topic](https://discourse.julialang.org/t/type-stability-when-arguments-are-functions/4734)._
