I am writing a small little lib and I’m undecided on how to effectively document the public functions where there are multiple arity versions.
For example
def new(arg1), do: %{a: arg1}
def new(arg1, arg2), do: %{a: arg1, b: arg2}
Now this is a little contrived but I wondered what might be the best way to document these two functions. In the past I have put a @doc
on each function and just gone with some duplication in the doc wording. However in my case arg1
is expected to be within a range of values, lets say one of these two tuples :abc
or :xyz
. At this point I’m now having to document the accepted range in docs for both functions and I feel this is now too much duplication.
Maybe the approach is incorrect and I should be using a default param like so
def new(arg1, arg2 \\ ""), do: %{a: arg1, b: arg2}
Anyway, I am hoping someone may have figured out the desired approach for this kind of situation and has the sliver bullet answer