Return statement in Elixir

This is an interesting problem because you need to perform multiple checks, exit early, and in the process transform some state (connection). I typically approach this problem as follows: I implement each check as a function which takes state as an input and returns {:ok, new_state} or {:error, reason}. Then, I build a generic function … Read more

using a package locally with hex.pm

Yes it is. In your mix.exs, you can list the dependency with the :path keyword (very similarly to what you do with gems). def dependencies do [{:testing_dep, path: “/Users/me/testing_dep”}] end You can read a list of all the supported options (e.g., pulling the dependency from GitHub or from a Git repository) in the documentation for … Read more

Loop through a Map’s key-value pairs

Turns out you iterate over a Map exactly like you do over a Keyword List (i.e. you use a tuple): Enum.each(%{a: 1, b: 2, c: 3}, fn {k, v} -> IO.puts(“#{k} –> #{v}”) end) Comprehensions also work: for {k, v} <- %{a: 1, b: 2, c: 3} do IO.puts(“#{k} –> #{v}”) end Note: If you … Read more

Installing dependencies in Elixir

If you are looking for something similar to npm install –save, then this does not exist in Elixir. You install things by adding them to deps: in the mix.exs file in your project then running mix deps.get. The other way you may wish to install certain applications is via a mix archive allowing this mix … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)