# Function with a single method acting on Union{T1, T2} or another function with two methods, for T1 and T2?

**URL:** <https://discourse.julialang.org/t/function-with-a-single-method-acting-on-union-t1-t2-or-another-function-with-two-methods-for-t1-and-t2/52132>\
**Category:** New to Julia\
**Created:** [December 20, 2020, 3:07pm UTC](https://discourse.julialang.org/t/function-with-a-single-method-acting-on-union-t1-t2-or-another-function-with-two-methods-for-t1-and-t2/52132 "2020-12-20T15:07:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [December 20, 2020, 3:41pm UTC](https://discourse.julialang.org/t/function-with-a-single-method-acting-on-union-t1-t2-or-another-function-with-two-methods-for-t1-and-t2/52132/2 "2020-12-20T15:41:38Z")

</div>

This is similar to

> [@Method dispatch](https://discourse.julialang.org/t/method-dispatch/51709):
>
> Julia is a lot about multiple dispatching and I am having trouble to understand what an idiomatic way of using mulitple dispatch is. My question is for small methods if I should define two different methods or if I should just use if else statements? (i.e. if typeof(...)...) Example: I want to format/convert numbers or arrays of numbers into a string. Is the below approach reasonable? Or what is an idiomatic way to deal with the two cases (i) a single number and (ii) an array of things (e.g. n…

Generically, the `area2` approach has two benefits:

- it can be expanded to additional shapes
- it guarantees compile time dispatch (if the rest of the code is type stable)  
Perhaps the logical approach would be to set up `Square` and `Rectangle` as subtypes of `Quadrilateral`. But that depends on what else you are doing with those types.

---

_[View the full topic](https://discourse.julialang.org/t/function-with-a-single-method-acting-on-union-t1-t2-or-another-function-with-two-methods-for-t1-and-t2/52132)._
