Multi-head function spec

How to express a spec like this in elixir?

 -spec foo(T1, T2) -> T3
        ; (T4, T5) -> T6.
  @spec foo(t1, t2) :: t3
           (t4, t5) :: t6

doesn’t compile.

Sounds like:

Specifications can be overloaded just like ordinary functions.

@spec function(integer) :: atom
@spec function(atom) :: integer

(from Typespecs reference — Elixir v1.16.0)

4 Likes
@spec foo(t1, t2) :: t3
@spec foo(t4, t5) :: t6
3 Likes