AFAIK Dialyzer do not do any deductions about types. You can write:
@spec group_by(collection :: [t], by :: ((t) -> key)) :: %{required(key) => t} when t: term(), key: term()
But Dialyzer will not be able to deduce that key
or t
needs to be the same, this will be only visible to the user. Of course you do not need to use Dialyzer and instead use other tools (like Gradualizer) or even write your own that will make deductions about code, but AFAIK there is no such tool right now.