José Valim josevalim

View gist:11173516

Before

A map pattern will match any map that has the given keys and values. For example, %{"hello" => world} will match any map that has the key "hello". An empty map therefore matches all maps.

After

A map pattern will match any map that has all the keys specified in the pattern. The values for the matching keys must also match. For example, %{"hello" => world} will match any map that has the key "hello" and assign the value to world, while %{"hello" => "world"} will match any map that has the key"hello"with value equals to"world". An empty map pattern (%{}`) will match all maps.

View pdict.diff
1 2 3 4 5 6 7 8 9 10
diff --git a/lib/task/sup.ex b/lib/task/sup.ex
index 3070aa2..4cc4968 100644
--- a/lib/task/sup.ex
+++ b/lib/task/sup.ex
@@ -66,10 +66,14 @@ defmodule Task.Sup do
"""
@spec async(Supervisor.supervisor, module, atom, [term]) :: Task.t
def async(supervisor, module, fun, args) do
- { :ok, pid } = Supervisor.start_child(supervisor, [self(), { module, fun, args }])
+ lock = make_ref()
View 1_gen_server.ex
1 2 3 4 5 6 7 8 9 10
defmodule Mix.TasksServer do
@moduledoc false
use GenServer.Behaviour
 
def start_link() do
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, :ok, [])
end
 
def clear_tasks() do
call :clear_tasks
View gen_event.diff
1 2 3 4 5 6 7 8 9 10
diff --git a/lib/gen_event.ex b/lib/gen_event.ex
index bc2a34f..07ca53f 100644
--- a/lib/gen_event.ex
+++ b/lib/gen_event.ex
@@ -468,8 +468,12 @@ defimpl Enumerable, for: GenEvent do
send mon_pid, { :UP, mon_ref, self() }
receive do
- { :UP, ^mon_ref, manager_pid } -> { mon_ref, mon_pid, manager_pid }
- { :DOWN, ^mon_ref, _, _, reason } -> exit(reason)
View my_receive.exs
1 2 3 4 5 6 7 8 9 10
defmodule MyReceive do
defmacro my_receive(do: clauses) do
extra = quote do
other -> IO.puts "got #{inspect other}"
end
quote do
receive do: unquote(clauses ++ extra)
end
end
View seq_interleave.exs
1 2 3 4 5 6 7 8 9 10
defmodule Interleave do
def interleave(a, b) do
af = Seq.impl_for(a)
bf = Seq.impl_for(b)
do_interleave_1(af, a, bf, b, []) |> :lists.reverse()
end
defp do_interleave_1(af, a, bf, b, acc) do
case af.next(a) do
{ :next, i, a } ->
View rules.exs
1 2 3 4 5 6 7 8 9 10
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
 
# Store each rules in the @rules attribute so we can
View gist:6916427
1 2 3 4 5 6 7 8 9 10
% from my unit tests
 
foo = 10
 
assert 10 == my_macro(:foo)
assert 10 == my_macro("foo")
 
% macro
 
defmacro my_macro(some_var) when is_atom(some_var) do
View dict.behaviour.ex
1 2 3 4 5 6 7 8 9 10
defmodule Dict.Behaviour do
# It is assumed that the client module implements following functions:
#
# size/1, fetch/2, put/3, reduce/3, update/4, delete/2
#
defmacro __using__(_) do
quote do
# Following are exact copies of HashDict:
 
def get(dict, key, default // nil) do
View gist:6164033
1 2 3 4 5 6 7 8 9 10
defmodule ExCoder do
vars = [ { "	", " " },
{ "!", "!" },
{ "" "", "\"" },
{ "#", "#" },
{ "$", "$" },
{ "%", "%" },
{ "& &", "&" },
{ "'", "'" },
{ "(", "(" },
Something went wrong with that request. Please try again.