elixir KERNEL 3 Flashcards

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})

A

=> true

17
Q

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

A

=> 5

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})

A

=> 3

23
Q

var = “bon”

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

A

=> true

24
Q

port = Port.open(

{:spawn, “cat”},

[:binary]

)

is_port(port)

A

=> true

25
Q

~S(b#{o}n)

A

=> “b#{o}n”

*Note: Returns a string without escaping characters
and without interpolations.

26
Q

raise(ArgumentError, message: “Error details”)

A

** (ArgumentError)
Error details

27
Q

nil || 2

A

=> 2

*Note: Returns the second expression only if the first one is false or nil

28
Q

d = “dog”

~w(cat #{d} bird)

A

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

*Note: Returns a list of “words” split by whitespace. Character unescaping and interpolation happens for each word.

29
Q

x = 1

match?(^x, 1)

A

=> true

30
Q

~N[2015-01-13T13:00:07.001]

A

=> ~N[2015-01-13 13:00:07.001]

*Note: Sigil ~N for naive date times

31
Q

Enum.empty?([1]) || 1

A

=> 1

*Note: Returns the second expression only if the first one is false or nil

32
Q

function_exported?(

Calc,

:add,

2

)

A

=> false

*Note: Returns true if module is loaded and contains a public function with the given arity.

33
Q

~W(cat dog bird)a

A

=> [:cat, :dog, :bird]

*Note: modifier a - words in the list are atoms.

34
Q

~w(cards config test.exs)

A

=> [“cards”, “config”, “test.exs”]