Powered by AppSignal & Oban Pro

Untitled notebook

untitled_notebook.livemd

Untitled notebook

Section

list = [1, 2, 3]
case Enum.at(list, 2) do
  1 -> "this won't print"
  3 -> "3 is a match!"
  _ -> "catch all" 
end
defmodule Post do
  defstruct(
    id: nil,
    title: "",
    description: "",
    author: ""
  )
end
post1 = %Post{id: 1, title: "Title No 1", author: "Julius Ceaser"}
case post1 do
  %{author: "Ali"} -> "Got a post from Ali"
  %{author: "Veli"} -> "Got a post from Veli"
  _ -> "Got a post from #{post1.author}"
end 
post1 = %{post1 | author: "Ali"}
case post1 do
  %{author: "Ali"} -> "Got a post from Ali"
  %{author: "Veli"} -> "Got a post from Veli"
  _ -> "Got a post from #{post1.author}"
end 
cond do
  post1.author == "Ali" -> "Editing a post from Ali"
  post1.author == "Veli" -> "Editing a post from Veli"
  true -> "This is a catch all"  
end
 cond do
   hd(list) == 1 -> "Got a 1"
   true -> "Head is #{hd(list)}"  
 end
if true do
  "This will work"
else
  "Else this will work"
end