Today I Learned

hashrocket A Hashrocket project

Guard Clause on Elixir Typespec

TIL that Elixir has some type of guard clause for typespec:

defmodule TupleMaker do
  @spec build(arg1, arg2) :: {arg1, arg2} when arg1: atom, arg2: integer | binary
  def build(arg1, arg2), do: {arg1, arg2}
end

I still prefer to use @type instead, but itโ€™s always useful to know alternatives.

See More #elixir TILs
Looking for help? At Hashrocket, we ๐Ÿ’œ Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.