# Dispatch on all binary operations

**URL:** <https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269>\
**Category:** New to Julia\
**Created:** [July 18, 2020, 12:45am UTC](https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269 "2020-07-18T00:45:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnderGray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andergray/32/20928_2.png) [@AnderGray](https://discourse.julialang.org/u/AnderGray)\
**Post date:** [July 18, 2020, 12:45am UTC](https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269/1 "2020-07-18T00:45:52Z")

</div>

Hi all, been using Julia for sometime now, first time I’m posting here.

Is it possible for me to dispatch over all binary operations which have specific type arguments?

I’m working on a Fuzzy Arithmetic package, where Fuzzy Numbers are effectively a nested array of intervals but you do some funky stuff to the membership function.

I’ve got a method function which takes two Fuzzy numbers and a binary operation and computes the resulting fuzzy number

```julia
minMaxConv(x :: FuzzyNumber, y :: FuzzyNumber; op = +)

```

op can be any operation defined for an interval from IntervalArithmetic.jl.

Is there anyway I can dispatch on all binary operations from defined for type `Interval` instead of having to do:

```nohighlight
+( x :: FuzzyNumber, y :: FuzzyNumber) = minMaxConv(x, y, op = +)

```

Cheers 🙂

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 18, 2020, 12:51am UTC](https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269/2 "2020-07-18T00:51:10Z")

</div>

The easiest is to define the methods in a for loop using metaprogramming.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 18, 2020, 12:55am UTC](https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269/3 "2020-07-18T00:55:59Z")

</div>

happen to have an [example](https://github.com/JuliaStats/StatsBase.jl/blob/6f9952d5c9a92faa851822b2e06051f7fc59c294/src/hist.jl#L226-L230) at hand

---

<div class="post-metadata">

**Author:** ![AnderGray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andergray/32/20928_2.png) [@AnderGray](https://discourse.julialang.org/u/AnderGray)\
**Post date:** [July 18, 2020, 1:05am UTC](https://discourse.julialang.org/t/dispatch-on-all-binary-operations/43269/4 "2020-07-18T01:05:19Z")

</div>

Wonderfull, thank you both
