Skip to content

Instantly share code, notes, and snippets.

View costaraphael's full-sized avatar

Raphael Costa costaraphael

View GitHub Profile
@costaraphael
costaraphael / nice_pattern.exs
Created May 10, 2019 01:12
Builder pattern in Elixir (don't do this!!!)
defmodule Person do
defstruct [:name, :age]
def with do
{Person.Builder, %{}}
end
defmodule Builder do
def unquote(:'$handle_undefined_function')(:and_with, [{__MODULE__, _acc} = tuple]) do
tuple
@costaraphael
costaraphael / permutations.ex
Created May 8, 2018 21:42
Calculating permutations in Elixir
defmodule Permutations do
def permutate([]), do: [[]]
def permutate(list) do
for n <- list,
p <- permutate(list -- [n]),
do: [n | p]
end
end