Section 1

Preview this deck

what does carat "^" sign do in elixir

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (24)

Section 1

(24 cards)

what does carat "^" sign do in elixir

Front

refers to the previously mentioned variable in scope fn (pid) -> receive do { ^pid } -> :do_stuff end the value of pid in the arguement is referred in the receive case of tuple

Back

Module namespaces in Elixir are

Front

atoms

Back

Book approach on making modules

Front

- The API - Logic of the service (semi abstract-class) - implementation of the logic in the server

Back

:registered option in mix application

Front

"The registered: option lists the names that our application will register. We can use this to ensure each name is unique across all loaded applications in a node or cluster. In our case, the sequence server registers itself under the name Sequence.Server, so we'll update the configuration to read as follows:" Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

Property based test - shrink

Front

If first condition fails, narrow down the next generated data to a more "reasonable" condition

Back

Process.monitor vs spawn_monitor

Front

Process.monitor can cause race condition where the process you are trying to monitor exits " The spawn_link and spawn_monitor versions are atomic, however, so you'll always catch a failure." Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

Elixir Design Philosophy for exceptions

Front

errors should propagate back up to the external, supervising process

Back

Full syntax of import

Front

"​import Module [, only:|except: ]" Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

rules on controllers and atom vs string as keys

Front

"External data can't safely be converted to atoms, because the atom table isn't garbage-collected. Instead, we explicitly match on the string keys, and then our application boundaries like controllers and channels will convert them into atom keys, which we'll rely on everywhere else inside Phoenix." Excerpt From: Chris McCord, Bruce Tate, José Valim. "Programming Phoenix ≥ 1.4 (for Sang Chun)." Apple Books.

Back

Order of parameters when using |>

Front

"The |> operator takes the result of the expression to its left and inserts it as the first parameter of the function invocation to its right." Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

Prying in elixir

Front

require​ IEx; IEx.pry or you can use "break! Module.method/arity" in iex

Back

Updating maps can only

Front

update keys that do exist. HAve to use Map.put_new to introduce a new key

Back

5 Questions of elixir strategy

Front

"What is the environment and what are its constraints? What are the obvious focal points? What are the runtime characteristics? What do I protect from errors? How do I get this thing running?" Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

changeset in elixir

Front

Changesets allow filtering, casting, validation and definition of constraints when manipulating structs.

Back

Macro rule

Front

never use a macro when you could use a function

Back

pin operator

Front

key = :name %{ ^key => value } = %{ :name => "Sam } means we want to match against a specific version of the variable rather than binding to the variable

Back

How to Choose Between Maps, Structs, and Keyword Lists?

Front

Do I want to pattern-match against the contents (for example, matching a dictionary that has a key of :name somewhere in it)? - If so, use a map. Will I want more than one entry with the same key? - If so, you'll have to use the Keyword module. Do I need to guarantee the elements are ordered? - If so, again, use the Keyword module. Do I have a fixed set of fields (that is, is the structure of the data always the same)? - If so, use a struct. Otherwise, if you've reached this point - Use a map.

Back

When are changeset constraints useful?

Front

Changesets allow filtering, casting, validation and definition of constraints when manipulating structs. otherwise you should just let it crash instead of being over-eager to validate the database inputs

Back

You can add github repo as dependency

Front

{ :dep_name, github: "user/repo_name" }

Back

Property based test - element

Front

similar to shrink but reversed in direction

Back

When using default parameters

Front

Add a function head with no body that contains the default parameters, and use regular parameters for the rest.

Back

Plug#init runs at

Front

compile time

Back

When do you use agents and tasks, and when do you use a GenServer?

Front

"The answer is to use the simplest approach that works. Agents and tasks are great when you're dealing with very specific background activities, whereas GenServers (as their name suggests) are more general. You can eliminate the need to make a decision by wrapping your agents and tasks in modules, as we did in our anagram example. That way you can always switch from the agent or task implementation to the full-blown GenServer without affecting the rest of the code base." Excerpt From: Dave Thomas. "Programming Elixir ≥ 1.6 (for Sang Chun)." Apple Books.

Back

How to convert a particular ecto prop to something else?

Front

Use Ecto.Type

Back