Skip to content

Instantly share code, notes, and snippets.


Eksperimental eksperimental

View GitHub Profile
View combine.exs
defmodule Variadic do
def spread_combine(h, f, g) do
{:arity, f_arity} =, :arity)
{:arity, g_arity} =, :arity)
args = Macro.generate_arguments(f_arity + g_arity, __MODULE__)
{f_args, g_args} = Enum.split(args, f_arity)
fn_ast =
eksperimental / variadic.exs
Last active Mar 19, 2021
Build anonymous functions with a variable length of arguments
View variadic.exs
defmodule Variadic do
@moduledoc """
Solution for
defmacro spread_combine(h, f, g) do
quote bind_quoted: [h: h, f: f, g: g, module: __CALLER__.module],
location: :keep do
{:arity, f_arity} =, :arity)
{:arity, g_arity} =, :arity)
eksperimental / typespec_example.ex
Last active Jul 2, 2020
Broken types in Elixir Issue #10140
View typespec_example.ex
# Downloaded from:
# Lists all the types that have the problem reported in
# create an Elixir project, and save this file in lib/typespec_example.ex
# Start IEx with: iex -S mix
# then run: TypespecExample.types()
# and paste the output into the shell.
defmodule TypespecExample do
eksperimental / gist:701103fc9e723fddc0bfeb757ecb1e7d
Created May 25, 2017
What modules implement the Enumerable and Collectable protocols in Elixir
View gist:701103fc9e723fddc0bfeb757ecb1e7d
elixir$ ag "defimpl\s+Collectable" -G ".ex$"
247:defimpl Collectable, for: HashDict do
35: defimpl Collectable do
eksperimental / .editorconfig
Last active Feb 25, 2019
.editorconfig for Elixir projects
View .editorconfig
# EditorConfig is awesome:
# .editorconfig for Elixir projects
# top-most EditorConfig file
root = true
indent_style = space
eksperimental / record_file.exs
Created Sep 23, 2016
How to parse a text file with pattern matching, and converted to a nested list
View record_file.exs
defmodule RecordFile do
def read(file) do
{:ok, data} =
|> String.split("\n")
|> filter
eksperimental / guard_helpers.ex
Last active Aug 13, 2016 — forked from christhekeele/guard_helpers.ex
A defguard macro written for Elixir v0.11.something a while back. I don't remember anything breaking at the time. Written for a library that was supposed to help AST transformations, in part by creating guards for particular AST constructs.
View guard_helpers.ex
defmodule Guard.Helpers do
@moduledoc """
Tools for creating custom guards.
@doc """
Creates a macro that's aware of its presence in a guard.
Taken from,
eksperimental /
Last active Aug 11, 2016
## Introducing is_kind/2, and operators: is, is_not, is_any, are, are_not, are_any

Introducing is_kind/2, and operators: is, is_not, is_any, are, are_not, are_any

Guards clauses are a key feature in Elixir. Researching how to make it easier for developers to define guards, has led me to two enhancement proposal. This is the first one, which will allow developers to write guards, guard-safe macros and regular expressions in a more natural and succinct way.


The following macro is allowed in guards:

  • is_kind(term, kind) determines if a given term is of a certain kind.

as well as the following operators:

  • term is kinds determines if term is each kind in kinds.
View enum_slice_bench.exs
defmodule Data do
@slice_counts [0, 1, 100, 990, ]
@terms [
:range, :range_single, :range_big, :range_huge,
:list, :list_empty, :list_single, :list_big, :list_huge,
:map, :map_empty, :map_single, :map_big, :map_huge,
:struct, :struct_empty, :struct_single, :struct_big, :struct_huge,
eksperimental / enum_fetch.ex
Last active Jul 16, 2016
Enum.fetch/2 Optimizations
View enum_fetch.ex
defmodule EnumFetchHelpers do
## fetch
def fetch_list([], _index),
do: :error
def fetch_list([head | _], 0),
do: {:ok, head}
def fetch_list([_ | tail], index),
do: fetch_list(tail, index - 1)