elixirtypespec

Code style for long typespecs


Which is the code style for a long typespec which exceed 80 characters length?

@spec function(list() | map(), list() | map(), list() | map(), list() | nil) :: map()

Solution

  • Here's the example from Enum module. You might want to do something similar to this

    @spec chunk_while(
              t,
              acc,
              (element, acc -> {:cont, chunk, acc} | {:cont, acc} | {:halt, acc}),
              (acc -> {:cont, chunk, acc} | {:cont, acc})
            ) :: Enumerable.t()
            when chunk: any