Mix.install([
{:torchx, "~> 0.1.0-dev", github: "elixir-nx/nx", sparse: "torchx"},
{:nx, "~> 0.1.0-dev", github: "elixir-nx/nx", sparse: "nx", override: true}
])
This file contains 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
TEST_COUNT ?= 4 | |
test: | |
ifeq ($(TEST_COUNT), 2) | |
exit 0; | |
else | |
exit 1; | |
endif | |
retry-test: |
This file contains 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
defmodule X do | |
@moduledoc """ | |
iex> X.a | |
"happy_emoji" | |
""" | |
Enum.each( | |
[:"😀"], | |
fn (name) -> | |
def unquote(name)(), do: "happy_emoji" |
This file contains 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
defmodule MakeBehaviour do | |
defmacro __using__(opts) do | |
module = opts[:module] | |
quote do | |
if not is_nil(unquote(module)) do | |
import unquote(module) | |
end | |
@on_definition {MakeBehaviour, :on_def} | |
end | |
end |
This file contains 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
defmodule Web.CardParams do | |
defstruct holder_name: "name", | |
last_digits: "1234", | |
address: %Web.AddressParams{street: "rua dos bobos", number: "zero"} | |
@enforce_keys [:holder_name, :last_digits, :address] | |
# esse cara aqui pra mim é problemático | |
# Ou você continua dependendo do Core.Address | |
# ou você tem que tirar o nome da struct e passar um map |
This file contains 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
defmodule MultiBoolComp do | |
@moduledoc """ | |
Defines an `sequential_bool` macro that parses a sequence of boolean comparisons in-line, such as: | |
`sequential_bool(a < b >= c == d <= e)` which would be equivalent to `a < b and b >= c and c == d and d <= e` | |
Only the native comparators are accepted (<, >, <=, >=, ==, !=, ===, !==) | |
### Examples: | |
iex> MultiBoolComp.sequential_bool(1 <= 4) | |
true |
This file contains 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
defmodule Incrementer do | |
@moduledoc """ | |
We need to define this macro separately so we have a fully-qualified name | |
to call it in a stable manner. Otherwise, the module would have to recursively | |
(and infinitely) define this macro, which would in turn define the module itself. | |
""" | |
defmacro gen_module(value, state_holder_module_name) do | |
quote bind_quoted: [value: value, state_holder_module_name: state_holder_module_name] do | |
defmodule state_holder_module_name do | |
require Incrementer |
This file contains 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
defmodule Observable do | |
defmacro __using__(opts) do | |
subscriber_modules = opts[:subscriber_modules] | |
function = opts[:observable_function] | |
tag = opts[:tag] | |
{f, _} = Code.eval_quoted(function) | |
arity = f |> :erlang.fun_info() |> Keyword.get(:arity) |
This file contains 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
defmodule Effect do | |
defstruct subscribers: [], payload: nil | |
end | |
defmodule EffectHandler do | |
@callback handle(effect :: Effect.t()) :: :ok | {:error, reason :: term()} | |
defmacro __using__(effectful_function: [{effectful_function, 0}]) do | |
quote do | |
def main do |
This file contains 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
defmodule TesteTest do | |
use ExUnit.Case | |
setup_all do | |
# we want all tests to use the same admin id | |
admin_id = Ecto.UUID.generate() | |
%{x: 1, admin_id: admin_id} | |
end |
OlderNewer