elixir KERNEL 3 Flashcards

(34 cards)

1
Q

to_charlist(:hello)

A

=> ‘hello’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

x = %{“data” => %{user: %{id: 1}}}

pop_in(x[“data”][:user][:id])

A

=> {1, %{“data” => %{user: %{}}}}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

trunc(-1.45)

A

=> -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

~w(cat #{“ dog bird “})

A

=> [“cat”, “dog”, “bird”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

body = %{“data” => %{id: 1}}

x = pop_in(body[“data”][:id])

y = pop_in(body, [“data”, :id])

x == y

A

=> true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

~w(cat #{:dog} bird)

A

=> [“cat”, “dog”, “bird”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

tl([1, 2, 3])

A

=> [2, 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

send self(), “hello”

A

=> “hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

bit_size(<<1, 2, 3>>)

A

=> 24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

unless 1 + 2 == 3, do: “hey”

A

=> nil

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

binary_part(“flashcards”, 0, 5)

A

=> “flash”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

binary_part(“hello you”, 9, -3)

A

=> “you”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

unless 1 + 2 == 3 do

“hello”

else

“good bye”

end

A

=> “good bye”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

unless 1 + 2 == 5, do: “hey”

A

=> “hey”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

match?(“h”, “h”)

A

=> true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

match?({:a, 1}, {:a, 1})

17
Q

bit_size(<<1::2, 2::3>>)

18
Q

Atom.to_string :hello |> String.upcase

A

** (FunctionClauseError)

no function clause matching in String.upcase/2

*Note: |> has higher precedence.
Therefore :hello is applied to String.upcase first.

19
Q

x = %{“data” => %{user: %{id: 1}}}

pop_in(x, [“data”, :user, :id])

A

=> {1, %{“data” => %{user: %{}}}

20
Q

x = %{“y” => %{user: %{id: 1}}}

put_in(x[“y”][:user][:id], 2)

A

=> %{“y” => %{user: %{id: 2}}}

21
Q

try do

raise “hello”

rescue

e in [RuntimeError] -> “caught you!”

end

A

=> “caught you!”

22
Q

tuple_size({1, “h”, :a})

23
Q

var = “bon”

Regex.match?(~r/bbon/, “rib#{var}”)

24
Q

port = Port.open(

{:spawn, “cat”},

[:binary]

)

is_port(port)

25
~S(b#{o}n)
=\> "b\#{o}n" \*Note: Returns a string without escaping characters and without interpolations.
26
raise(ArgumentError, message: "Error details")
\*\* (ArgumentError) Error details
27
nil || 2
=\> 2 \*Note: Returns the second expression only if the first one is false or nil
28
d = "dog" ~w(cat #{d} bird)
=\> ["cat", "dog", "bird"] ## Footnote \*Note: Returns a list of "words" split by whitespace. Character unescaping and interpolation happens for each word.
29
x = 1 match?(^x, 1)
=\> true
30
~N[2015-01-13T13:00:07.001]
=\> ~N[2015-01-13 13:00:07.001] \*Note: Sigil ~N for naive date times
31
Enum.empty?([1]) || 1
=\> 1 \*Note: Returns the second expression only if the first one is false or nil
32
function\_exported?( Calc, :add, 2 )
=\> false \*Note: Returns true if module is loaded and contains a public function with the given arity.
33
~W(cat dog bird)a
=\> [:cat, :dog, :bird] \*Note: modifier a - words in the list are atoms.
34
~w(cards config test.exs)
=\> ["cards", "config", "test.exs"]