IEx.Helpers.import_file_if_available
You're seeing just the macro
import_file_if_available
, go back to IEx.Helpers module for more information.
Similar to import_file
but only imports the file if it is available.
By default, import_file/1
fails when the given file does not exist.
However, since import_file/1
is expanded at compile-time, it's not
possible to conditionally import a file since the macro is always
expanded:
# This raises a File.Error if ~/.iex.exs doesn't exist.
if "~/.iex.exs" |> Path.expand() |> File.exists?() do
import_file("~/.iex.exs")
end
This macro addresses this issue by checking if the file exists or not in behalf of the user.