Skip to content

Instantly share code, notes, and snippets.

View koudelka's full-sized avatar
💭
一所懸命働いているん

Michael Shapiro koudelka

💭
一所懸命働いているん
View GitHub Profile
@koudelka
koudelka / lookup.ex
Created October 2, 2015 21:13
Elixir Set Lookup
defmodule Lookup do
@wordfile "words.txt"
@external_resource @wordfile
@times 1_000_000
@words @wordfile |> File.stream! |> Enum.map(&String.strip/1)
@hash_set Enum.into(@words, HashSet.new)
@map_set Enum.into(@words, MapSet.new)
@koudelka
koudelka / type_bully.exs
Created March 12, 2016 00:21
TypeBully is an (incomplete) toy module to force Elixir functions to respect their typespecs.
#
# TypeBully forces functions to respect their typespecs by rewriting the function clauses to include proper guards.
#
# For example, the Wimp module below: cry/3 has typespecs, but no enforcing guards, normally, calling cry/3 would
# always match the first function clause, but TypeBully forces it to select the correct one based on its typespec.
#
#
# Without TypeBully:
#
# iex(1)> Wimp.cry("whaa")