Jose Valim talk about features of Elixir 1.5
break!open
| tmux ls && read tmux_session && tmux attach -t ${tmux_session:-default} || tmux new -s ${tmux_session:-default} |
| JSONPrinter.print(~s/{"hello": "goodbye"}/) |
| defmodule JSONPrinter do | |
| use FilePrinter | |
| @behaviour FilePrinter | |
| @impl FilePrinter | |
| def parse(str), do: {:ok, "some json " <> str} # ... parse JSON | |
| @impl FilePrinter | |
| def extensions, do: ["json"] |
| defmodule FilePrinter do | |
| @callback parse(String.t) :: {:ok, term} | {:error, String.t} | |
| @callback extensions() :: [String.t] | |
| defmacro __using__(_opts) do | |
| quote do | |
| def output(parsed_str) do | |
| IO.puts(parsed_str) | |
| end |
| defmodule Parser do | |
| @callback parse(String.t) :: {:ok, term} | {:error, String.t} | |
| @callback extensions() :: [String.t] | |
| end | |
| defmodule JSONParser do | |
| @behaviour Parser | |
| def parse(str), do: {:ok, "some json " <> str} # ... parse JSON | |
| def extensions, do: ["json"] |
| defprotocol Size do | |
| @doc "Calculates the size (and not the length!) of a data structure" | |
| def size(data) | |
| end | |
| defimpl Size, for: BitString do | |
| def size(string), do: byte_size(string) | |
| end | |
| defimpl Size, for: Map do |
Jose Valim talk about features of Elixir 1.5
break!open| defmodule GherkinTests.Contexts.EditUser do | |
| use WhiteBread.Context | |
| alias GherkinTests.State | |
| given_ ~r/^I register a new user called "(?<name>[^"]+)"$/, | |
| fn state, %{name: name} -> | |
| user_details = %{name: name, email: "#{name}@example.com", password: "password123"} | |
| user_id = MyApp.register(user_details) |
| defmodule GherkinTests.State do | |
| def store(state, key, value), do: Map.put(state, key, value) | |
| def retrieve(state, key), do: Map.get(state, key) | |
| def set_if_not_exists(state, key, value) do | |
| if Map.has_key?(state, key) do | |
| state | |
| else |
| Feature: Changing user details | |
| Scenario: Changing first name to Bob | |
| Given I register a new user | |
| And I change their "name" to "Brian" | |
| When I change their "name" to "Bob" | |
| Then their "name" should be "Bob" | |
| Scenario: Changing first name to Charlie | |
| Given I register a new user |