# Priority in dispatch

**URL:** https://discourse.julialang.org/t/priority-in-dispatch/16065
**Category:** General Usage
**Created:** [October 9, 2018, 11:12am UTC](https://discourse.julialang.org/t/priority-in-dispatch/16065 "2018-10-09T11:12:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)
#### Post date: [October 9, 2018, 11:12am UTC](https://discourse.julialang.org/t/priority-in-dispatch/16065/1 "2018-10-09T11:12:52Z")

</div>

I have a famility of functions

```julia
b(t, x::T) = 

```

called in a loop

```julia
for i in 1:n 
   t = t + dt
   x = x + dt*f(t, x)
end

```

It turns out that sometimes I’d need the index `i` as well and I’d like to define

```julia
f((i,s)::Tuple, x) = f(s, x)
for i in 1:n 
   t = t + dt
   x = x + dt*f((i,s), x)
end

```

Which creates ambiguity between all my `f(s, x::T)` and `f((i,s)::Tuple, x)`. Of course I could  
play with the order of the arguments or use a different function name but just to be sure: is there a way do define

```julia
f((i,s)::Tuple, x) = f(s, x)

```

such it has higher priority than (say)

```julia
f(s, x::Float64) 

```

but less than `f((i,s)::Tuple, x::Float64)`?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [October 9, 2018, 12:16pm UTC](https://discourse.julialang.org/t/priority-in-dispatch/16065/3 "2018-10-09T12:16:34Z")

</div>

Instead of doing dispatch, can’t you just use a branch?

```julia
function f(s, x)
    s isa Tuple && return _f(s[2], x)
    return _f(s, x)
end

_f(s, x::Float64) = ...

```

---

<div class="post-metadata">

### Author: ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)
#### Post date: [October 9, 2018, 2:28pm UTC](https://discourse.julialang.org/t/priority-in-dispatch/16065/4 "2018-10-09T14:28:06Z")

</div>

Or using dispatch:

```julia
f((i,s)::Tuple, x) = f(s,x)
f(s,x) = _f(s,x)
_f(s, x::Float64) = ...
_f(s, ...) = ...

```
