Skip to content

Commit

Permalink
Change function type specification syntax (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information
yrashk authored and José Valim committed Nov 29, 2012
1 parent f1b81fd commit 0db1f72
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 236 deletions.
2 changes: 1 addition & 1 deletion lib/elixir/lib/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule Behaviour do
end

quote do
@callback unquote(name)(unquote_splicing(args)), do: unquote(return)
@callback unquote(name)(unquote_splicing(args)) :: unquote(return)
Behaviour.store_docs __MODULE__, unquote(__CALLER__.line), unquote(name), unquote(arity)
end
end
Expand Down
30 changes: 15 additions & 15 deletions lib/elixir/lib/dict.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Dict do
Dict.keys d #=> [:a,:b]
"""
@spec keys(t), do: [key]
@spec keys(t) :: [key]
def keys(dict) do
elem(dict, 0).keys(dict)
end
Expand All @@ -69,7 +69,7 @@ defmodule Dict do
Dict.values d #=> [1,2]
"""
@spec values(t), do: [value]
@spec values(t) :: [value]
def values(dict) do
elem(dict, 0).values(dict)
end
Expand All @@ -83,7 +83,7 @@ defmodule Dict do
Dict.size d #=> 2
"""
@spec size(t), do: non_neg_integer
@spec size(t) :: non_neg_integer
def size(dict) do
elem(dict, 0).size(dict)
end
Expand All @@ -98,7 +98,7 @@ defmodule Dict do
Dict.has_key?(d, :b) #=> false
"""
@spec has_key?(t, key), do: boolean
@spec has_key?(t, key) :: boolean
def has_key?(dict, key) do
elem(dict, 0).has_key?(dict, key)
end
Expand All @@ -115,8 +115,8 @@ defmodule Dict do
Dict.get d, :b, 3 #=> 3
"""
@spec get(t, key), do: value | nil
@spec get(t, key, value), do: value
@spec get(t, key) :: value | nil
@spec get(t, key, value) :: value
def get(dict, key, default // nil) do
elem(dict, 0).get(dict, key, default)
end
Expand All @@ -132,7 +132,7 @@ defmodule Dict do
Dict.get d, :b #=> raises KeyError[key: :b]
"""
@spec get!(t, key), do: value | no_return
@spec get!(t, key) :: value | no_return
def get!(dict, key) do
elem(dict, 0).get!(dict, key)
end
Expand All @@ -148,7 +148,7 @@ defmodule Dict do
#=> [a: 3, b: 2]
"""
@spec put(t, key, value), do: t
@spec put(t, key, value) :: t
def put(dict, key, val) do
elem(dict, 0).put(dict, key, val)
end
Expand All @@ -166,7 +166,7 @@ defmodule Dict do
Dict.delete d, :a #=> [b: 2]
"""
@spec delete(t, key), do: t
@spec delete(t, key) :: t
def delete(dict, key) do
elem(dict, 0).delete(dict, key)
end
Expand All @@ -185,7 +185,7 @@ defmodule Dict do
#=> [a: 3, b: 2, d: 4]
"""
@spec merge(t, t), do: t
@spec merge(t, t) :: t
def merge(dict1, dict2) do
merge(dict1, dict2, fn(_k, _v1, v2) -> v2 end)
end
Expand All @@ -204,7 +204,7 @@ defmodule Dict do
#=> [a: 4, b: 2, d: 4]
"""
@spec merge(t, t, fun(key, value, value, do: value)), do: t
@spec merge(t, t, fun(key, value, value) :: value) :: t
def merge(dict1, dict2, fun) do
elem(dict1, 0).merge(dict1, dict2, fun)
end
Expand All @@ -220,7 +220,7 @@ defmodule Dict do
#=> [a: -1, b: 2]
"""
@spec update(t, key, fun(value, do: value)), do: t
@spec update(t, key, fun(value) :: value) :: t
def update(dict, key, fun) do
elem(dict, 0).update(dict, key, fun)
end
Expand All @@ -237,15 +237,15 @@ defmodule Dict do
#=> [a: 1, b: 2, c: 3]
"""
@spec update(t, key, value, fun(value, do: value)), do: t
@spec update(t, key, value, fun(value) :: value) :: t
def update(dict, key, initial, fun) do
elem(dict, 0).update(dict, key, initial, fun)
end

@doc """
Returns an empty dict of the same type as `dict`.
"""
@spec empty(t), do: t
@spec empty(t) :: t
def empty(dict) do
elem(dict, 0).empty(dict)
end
Expand All @@ -254,7 +254,7 @@ defmodule Dict do
Returns a list of key-value pairs stored in `dict`.
No particular order is enforced.
"""
@spec to_list(t), do: list
@spec to_list(t) :: list
def to_list(dict) do
elem(dict, 0).to_list(dict)
end
Expand Down
Loading

0 comments on commit 0db1f72

Please sign in to comment.