Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

alias, require, import

platzi/alias-require-import.livemd

alias, require, import

alias

defmodule Math.List do
end
defmodule Stats do
  alias Math.List, as: List
end
alias Math.List as: List
alias Math.List

require

Integer.is_odd(3)
require Integer
Integer.is_odd(3)

import

import Elixir.List, only: [duplicate: 2]
duplicate(:ok, 3)
defmodule Math do
  def some_function do
    import Elixir.List, only: [duplicate: 2]
    duplicate(:ok, 3)
  end
end
Math.some_function()

module nesting & multi alias, require, import

defmodule Foo do
  defmodule Bar do
    def sum(a, b) do
      a + b
    end
  end
end
defmodule Foo.Bar do
  def sum(a, b) do
    a + b
  end
end

defmodule Foo do
  alias Foo.Bar
  # Bar.sum(a, b)
end

multi alias, require, import

# MyApp.Foo
# MyApp.Bar
# MyApp.Baz

alias MyApp.{Foo, Bar, Baz}