bessey / bt-elixir

Learning Elixir via building a BitTorrent client
3 stars 1 forks source link

Types on structs #3

Open mpope9 opened 4 years ago

mpope9 commented 4 years ago

I like types :D Makes understanding what is going on in structs way easier.

defmodule Examples do
  defstruct first: nil, last: nil

  @type t(first, last) :: %Examples{first: first, last: last}

  @type t :: %Examples{first: integer, last: integer}
end

As an example. Makes thing easier if you choose to run https://github.com/jeremyjh/dialyxir