# Julian way to check for valid combination of inputs when defining function

**URL:** <https://discourse.julialang.org/t/julian-way-to-check-for-valid-combination-of-inputs-when-defining-function/62267>\
**Category:** New to Julia\
**Created:** [June 2, 2021, 11:57am UTC](https://discourse.julialang.org/t/julian-way-to-check-for-valid-combination-of-inputs-when-defining-function/62267 "2021-06-02T11:57:23Z")\
**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:** [June 2, 2021, 12:22pm UTC](https://discourse.julialang.org/t/julian-way-to-check-for-valid-combination-of-inputs-when-defining-function/62267/2 "2021-06-02T12:22:16Z")

</div>

You may want a parametric type:

```julia
struct Relation{n}
  R :: Set
end

Base.union(r1 :: Relation{n}, r2 :: Relation{n}) where n = [...]
Base.union(r1 :: Relation{n1}, r2 :: Relation{n2}) where {n1, n2} = [...]

```

But this may take your example too literally.

For more complicated cases, Traits may work (e.g., [GitHub - mauro3/SimpleTraits.jl: Simple Traits for Julia](https://github.com/mauro3/SimpleTraits.jl)). But it depends on exactly what the comparison is.

As for extending Base functions, there are various threads here on discourse, such as

> [@Extending the standard library](https://discourse.julialang.org/t/extending-the-standard-library/18480/3):
>
> When you are worried about type piracy, you can also use ForceImport to make it an optional extension, [https://github.com/chakravala/ForceImport.jl](https://github.com/chakravala/ForceImport.jl) Which I previously explained on here before This way you don’t have to extend the Base methods by default and modified methods can be located inside your custom module; while giving the option to locally force their import contained in a namespace with @force using Module, giving you the best of both worlds locally and globally.

---

_[View the full topic](https://discourse.julialang.org/t/julian-way-to-check-for-valid-combination-of-inputs-when-defining-function/62267)._
