Oleksandr Rozumii, Toptal
$ mix new kv --module KV
* creating mix.exs
* creating config/config.exs
* creating lib/kv.ex
* creating test/test_helper.exs
* creating test/kv_test.exs
defmodule KV.Mixfile do
use Mix.Project
def application do
[applications: [:logger]]
end
defp deps do
[{:postgrex, ">= 0.0.0"}]
end
end
defmodule MyPlug do
def init([]), do: false
def call(conn, _opts), do: conn
end
defmodule App.Router do
use App.Web, :router
use Plug.ErrorHandler
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
iex> x = 1
1
iex> 1 = x
1
iex> 2 = x
** (MatchError) no match of right hand side value: 1
# Lists
iex> list = [1, 2, 3]
iex> [1, 2, 3] = list
[1, 2, 3]
iex> [] = list
** (MatchError) no match of right hand side value: [1, 2, 3]
iex> [1|tail] = list
[1, 2, 3]
iex> tail
[2, 3]
iex> [2|_] = list
** (MatchError) no match of right hand side value: [1, 2, 3]
defmodule Fib do
def fib(0) do 0 end
def fib(1) do 1 end
def fib(n) do fib(n-1) + fib(n-2) end
end
def tick(state, []) do
state
end
def tick(state, state) do
state
end
def tick(prev_state, curr_state) do
def event_text(%{"event" => "end", "label" => match_label}) do
I18n.t!("en", "bot.unavailable", label: label)
end
def event_text(%{"event" => "start", "label" => match_label}) do
I18n.t!("en", "bot.started", label: label)
end
def event_text(details = %{"match_id" => id, "event" => event}) do
children = [
supervisor(App.Endpoint, []),
worker(App.Repo, []),
supervisor(App.EventStore.Supervisor, []),
]
opts = [strategy: :one_for_one, name: App.Supervisor]
Supervisor.start_link(children, opts)