elixir KERNEL 3 Flashcards
(34 cards)
to_charlist(:hello)
=> ‘hello’
x = %{“data” => %{user: %{id: 1}}}
pop_in(x[“data”][:user][:id])
=> {1, %{“data” => %{user: %{}}}}
trunc(-1.45)
=> -1
~w(cat #{“ dog bird “})
=> [“cat”, “dog”, “bird”]
body = %{“data” => %{id: 1}}
x = pop_in(body[“data”][:id])
y = pop_in(body, [“data”, :id])
x == y
=> true
~w(cat #{:dog} bird)
=> [“cat”, “dog”, “bird”]
tl([1, 2, 3])
=> [2, 3]
send self(), “hello”
=> “hello”
bit_size(<<1, 2, 3>>)
=> 24
unless 1 + 2 == 3, do: “hey”
=> nil
binary_part(“flashcards”, 0, 5)
=> “flash”
binary_part(“hello you”, 9, -3)
=> “you”
unless 1 + 2 == 3 do
“hello”
else
“good bye”
end
=> “good bye”
unless 1 + 2 == 5, do: “hey”
=> “hey”
match?(“h”, “h”)
=> true
match?({:a, 1}, {:a, 1})
=> true
bit_size(<<1::2, 2::3>>)
=> 5
Atom.to_string :hello |> String.upcase
** (FunctionClauseError)
no function clause matching in String.upcase/2
*Note: |> has higher precedence.
Therefore :hello is applied to String.upcase first.
x = %{“data” => %{user: %{id: 1}}}
pop_in(x, [“data”, :user, :id])
=> {1, %{“data” => %{user: %{}}}
x = %{“y” => %{user: %{id: 1}}}
put_in(x[“y”][:user][:id], 2)
=> %{“y” => %{user: %{id: 2}}}
try do
raise “hello”
rescue
e in [RuntimeError] -> “caught you!”
end
=> “caught you!”
tuple_size({1, “h”, :a})
=> 3
var = “bon”
Regex.match?(~r/bbon/, “rib#{var}”)
=> true
port = Port.open(
{:spawn, “cat”},
[:binary]
)
is_port(port)
=> true