<aside> 💡 Mix Commands ❯ mix phx.new paymentapi --no-webpack --no-html: creates a new phx project ❯ mix deps.get: installs all depedencies ❯ mix php.server ❯ mix credo gen.config: generates the credo configuration
Database Commands ❯ mix ecto.create: creates the database ❯ mix ecto.drop: delete the database ❯ mix ecto.setup: checks the database ❯ mix ecto.gen.migration NAME_TABLE ❯ mix ecto.migrate: run the migrations ❯ Module.Repo: use databse commands
IEX Commands ❯ iex -S mix: access env on the terminal (recompile to update) ❯ on mix env: h Enum (return the documentation) ❯ alias Module.Name or alias Module.Name, as: Noob
</aside>
<aside> 📌 **Basic Concepts
Types
**
→ integer: 1
→ float: 1.1
→ boolean: true/false (nill)
→ atom (const): :name
→ string: always double quote
→ tuple: {3, 4, "apple"} **change the values costs much
→ list: [3, 4, :pil, "apple"]
→ maps: %{foo ⇒ "bar"} **duplicated keys are overrided
Operators
→ + - / * rem (divisor with rest)
→ && || > < ≠ == === (triple equals to integer and floats)
Functions
→ def name () do .... end
→ defp name () do ... end (not a public function)
→ def name (), do ... (syntax sugar)
→ (fn → name or not end) (anonymous function)
</aside>
<aside> 🗣 Highlights
→ IO.puts: prints values
→ (struct \\ %MODULE{}): default value → ^: pin operator, make a value fixed
→ interpolation: "Hello #{name}"
→ accessing maps properties: map.foo → update properties value on map: %{map | foo: "barz"}
→ prepeding element on list (faster): ["n", list] → appeding element on list: list ++ ["a"] → join lists: [1, 2] ++ [3,4] → remove from list: ["foo", "bar"] — ["foo"] → get first and last element: hd[list] and tl[list] → [head | tail] = list: split the list on head and tail → Enum: methods to list and tuples
</aside>
<aside> 🚂 Tasks → It is able to work with multi task and paralelism →Task.start(fn → end): when don't care the response → task = Task.async(fn → end) .... Task.await(task): dependencie of Task response
</aside>
<aside> 📢 Tests → mix test —cover → describe "name" do test "name" do assert end end → use Module.DataCase: on tests that use database and changeset → use ModuleWeb.ConnCase: on controllers tests
</aside>
<aside> 👌 Pattern Match: the left side should be the match to the right side [a, b, 3] = [1, 2, 3] %{b: valor} = %{a:1, b:2, c:3}
**with statement do ...end: used on patter match
</aside>
<aside> ☝ Immutability → Pipe Operator |>: get the first argument from previous function and pass to the next
</aside>