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
defmacro left |> right do | |
[{h, _} | t] = Macro.unpipe({:|>, [], [left, right]}) | |
fun = fn {x, pos}, acc -> | |
Macro.pipe(acc, x, pos) | |
end | |
:lists.foldl(fun, h, t) | |
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
case Modulo.funcao() do | |
{:ok, %User{role: "admin"} = user} -> | |
user |> faca_algo_com_admin() | |
{:ok, %User{role: "moderator"} = user} -> | |
user |> faca_algo_com_moderator() | |
{:ok, %User{role: "user"} = user} -> | |
user |> faca_algo_com_user() | |
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
# Alias the module so it can be called as Bar instead of Foo.Bar | |
alias Foo.Bar, as: Bar | |
alias MyApp.{Foo, Bar, Baz} | |
# Require the module in order to use its macros | |
require Foo | |
# Import functions from Foo so they can be called without the `Foo.` prefix | |
import Foo |
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> StackSupervisor.start_link | |
{:ok, #PID<0.230.0>} | |
iex> StackSupervisor.which_children | |
[ | |
{ProcessInElixir.StackNormal, #PID<0.231.0>, :worker, | |
[ProcessInElixir.StackNormal]} | |
] | |
iex> ProcessInElixir.StackNormal.push pid(0,231,0), "Japão" | |
{:push, "Japão"} | |
iex> ProcessInElixir.StackNormal.show pid(0,231,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
dataset = | |
[ | |
[lang: "C", loc: 79, t: {4, :s}, mem: {40, :MB}], | |
[lang: "Python", loc: 11, t: {4, :s}, mem: {150, :MB}], | |
[lang: "Ruby", loc: 9, t: {17, :s}, mem: {3, :GB}], | |
[lang: "Elixir", loc: 11, t: {120, :s}, mem: {700, :MB}], | |
[lang: "Elixir ETS", loc: 17, t: {40, :s}, mem: {730, :MB}], | |
[lang: "Elixir Regex", loc: 17, t: {70, :s}, mem: {730, :MB}], | |
[lang: "Elixir String.split", loc: 11, t: {30, :s}, mem: {730, :MB}], | |
[lang: "Elixir String.split pre-compiled", loc: 17, t: {29, :s}, mem: {730, :MB}], |
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(8)> code = quote do | |
...(8)> defmodule Util do | |
...(8)> def full_name(%User{} = user) do | |
...(8)> "#{user.first_name} #{user.last_name}" | |
...(8)> end | |
...(8)> end | |
...(8)> end | |
{:defmodule, [context: Elixir, import: Kernel], | |
[ | |
{:__aliases__, [alias: false], [:Util]}, |
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
leak1.ex: | |
defmodule Leak1 do | |
def leak do | |
x = 0 | |
if true do | |
x = 1 | |
end | |
x | |
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
Hello world | |
# hello.exs | |
defmodule Greeter do | |
def greet(name) do | |
message = "Hello, " <> name <> "!" | |
IO.puts message | |
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
defmodule Majom do | |
@constseq :lists.seq(1,10,2) | |
def f() do | |
IO.inspect(quote do | |
@constseq | |
end) | |
IO.inspect(@constseq) | |
end |