Skip to content

Instantly share code, notes, and snippets.

View leandrocp's full-sized avatar

Leandro Pereira leandrocp

View GitHub Profile
@leandrocp
leandrocp / art_bc_sales_customer_service.ex
Last active March 29, 2019 14:22
art_bc_sales_customer_service.ex
# 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()
@leandrocp
leandrocp / art_bc_support_public_api.ex
Last active November 14, 2018 09:59
art_bc_support_public_api.ex
# 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
@leandrocp
leandrocp / art_bc_customer_structs.ex
Last active March 29, 2019 14:18
art_bc_customer_structs
# 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
@leandrocp
leandrocp / art_bc_dir_structure
Created October 23, 2018 03:21
art_bc_dir_structure
➜ tree
.
├── README.md
├── apps
│   ├── sales
│   │   ├── README.md
│   │   ├── config
│   │   │   └── config.exs
│   │   ├── lib
│   │   │   └── sales.ex
@leandrocp
leandrocp / art_bc_create_apps
Created October 23, 2018 03:21
art_bc_create_apps
➜ cd system_x/apps
➜ mix new sales
➜ mix new support
@leandrocp
leandrocp / art_bc_create_umbrella_project
Last active October 23, 2018 03:38
art_bc_create_umbrella_project
➜ mix new system_x --umbrella
➜ cd system_x/apps
➜ mix new sales
➜ mix new support
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>],
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.
iex> :observer.start
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.