This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apps/sales/lib/client/support.ex | |
defmodule Sales.Client.Support do | |
alias Sales.Domain | |
def get_customer(%Domain.Customer{id: customer_id} = customer) do | |
customer_has_support_ticket = | |
customer_id | |
|> Support.get_customer() | |
|> has_support_ticket() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apps/support/lib/support.ex | |
defmodule Support do | |
def get_customer(customer_id) when is_integet(customer_id) do | |
find(customer_id) # get customer from db | |
|> Map.from_struct() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apps/sales/lib/domain/customer.ex | |
defmodule Sales.Domain.Customer do | |
defstruct [:id, :name, :address, :score, :has_support_ticket] | |
end | |
# apps/support/lib/domain/customer.ex | |
defmodule Support.Domain.Customer do | |
defstruct [:id, :name, :last_ticket_id, :email] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ tree | |
. | |
├── README.md | |
├── apps | |
│ ├── sales | |
│ │ ├── README.md | |
│ │ ├── config | |
│ │ │ └── config.exs | |
│ │ ├── lib | |
│ │ │ └── sales.ex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ cd system_x/apps | |
➜ mix new sales | |
➜ mix new support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ mix new system_x --umbrella | |
➜ cd system_x/apps | |
➜ mix new sales | |
➜ mix new support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex> defmodule Example, do: use GenServer | |
iex> {:ok, pid} = GenServer.start_link(Example, %{ping: "pong"}) | |
iex> Process.info pid | |
[ | |
current_function: {:gen_server, :loop, 7}, | |
initial_call: {:proc_lib, :init_p, 5}, | |
status: :waiting, | |
message_queue_len: 0, | |
messages: [], | |
links: [#PID<0.610.0>], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex>h Enum.map | |
def map(enumerable, fun) | |
@spec map(t(), (element() -> any())) :: list() | |
Returns a list where each item is the result of invoking fun on each | |
corresponding item of enumerable. | |
For maps, the function expects a key-value tuple. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex> :observer.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex> :sys.trace pid, true | |
:ok | |
iex> GenServer.call(pid, :next_number) | |
*DBG* <0.69.0> got call next_number from <0.25.0> | |
*DBG* <0.69.0> sent 105 to <0.25.0>, new state 106 | |
105 | |
# Excerpt From: Dave Thomas. “Programming Elixir ≥ 1.6” iBooks. |