Skip to content

Commit 0023998

Browse files
committed
Cleaned up type specs for dialyzer #4
1 parent 38be26d commit 0023998

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ language: erlang
22
notifications:
33
email: false
44
otp_release:
5-
- R14B03
6-
- R14B02
7-
- R14B01
5+
- R15B03
6+
- R16B01

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 0.2.3 released 2013-09-15
2+
3+
* Cleaned up type specs for dialyzer
4+
https://github.com/mochi/statebox/issues/4
5+
16
Version 0.2.2 released 2011-06-14
27

38
* Updated README

src/statebox.app.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{application, statebox,
22
[
33
{description, "Erlang state \"monad\" with merge/conflict-resolution capabilities. Useful for Riak."},
4-
{vsn, "0.2.2"},
4+
{vsn, "0.2.3"},
55
{registered, []},
66
{applications, [
77
kernel,

src/statebox.erl

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
last_modified :: timestamp()}).
2323
-opaque statebox() :: #statebox{}.
2424
-type event() :: {timestamp(), op()}.
25-
-type timestamp() :: integer().
25+
-type timestamp() :: statebox_clock:timestamp().
2626
-type timedelta() :: integer().
2727
-type basic_op() :: {module(), atom(), [term()]} |
2828
{fun((...) -> statebox()), [term()]}.
2929
-type op() :: basic_op() | [op()].
30+
-export_type([statebox/0, event/0, timestamp/0, timedelta/0, basic_op/0, op/0]).
3031

3132
%% Used in a test, must be done before function definitions.
3233
-ifdef(TEST).
@@ -35,7 +36,7 @@
3536

3637
%% @doc Return <code>true</code> if the argument is a statebox, <code>false</code>
3738
%% otherwise.
38-
-spec is_statebox(term()) -> boolean().
39+
-spec is_statebox(statebox() | term()) -> boolean().
3940
is_statebox(#statebox{}) ->
4041
true;
4142
is_statebox(_T) ->
@@ -46,6 +47,7 @@ is_statebox(_T) ->
4647
%% return an "empty" object of the desired type, such as
4748
%% <code>fun gb_trees:empty/0</code>.
4849
%% @equiv new(timestamp(), Constructor)
50+
-spec new(fun(() -> term())) -> statebox().
4951
new(Constructor) ->
5052
new(statebox_clock:timestamp(), Constructor).
5153

src/statebox_clock.erl

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44
-module(statebox_clock).
55
-export([timestamp/0, now_to_msec/1, now/0]).
66

7+
-type t_now() :: {integer(), integer(), integer()}.
8+
-type timestamp() :: integer().
9+
-export_type([t_now/0, timestamp/0]).
10+
711
-define(KILO, 1000).
812
-define(MEGA, 1000000).
913

1014
%% @doc Current UNIX epoch timestamp in integer milliseconds.
1115
%% Equivalient to <code>now_to_msec(os:timestamp())</code>.
12-
-spec timestamp() -> integer().
16+
-spec timestamp() -> timestamp().
1317
timestamp() ->
1418
now_to_msec(os:timestamp()).
1519

1620
%% @doc Converts given time of now() format to UNIX epoch timestamp in
1721
%% integer milliseconds.
18-
-spec now_to_msec(calendar:t_now()) -> integer().
22+
-spec now_to_msec(t_now()) -> timestamp().
1923
now_to_msec({MegaSecs, Secs, MicroSecs}) ->
2024
trunc(((MegaSecs * ?MEGA) + Secs + (MicroSecs / ?MEGA)) * ?KILO).
2125

22-
-spec now() -> calendar:t_now().
26+
-spec now() -> t_now().
2327
now() ->
2428
erlang:now().

src/statebox_identity.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-export([entropy/2, entropy/0]).
55

66
-type entropy() :: 1..4294967296.
7+
-export_type([entropy/0]).
78

89
%% @equiv entropy(node(), statebox_clock:now())
910
-spec entropy() -> entropy().
@@ -12,6 +13,6 @@ entropy() ->
1213

1314
%% @doc Return an integer that can be expected to be reasonably unique
1415
%% at a given msec timestamp.
15-
-spec entropy(node(), calendar:t_now()) -> entropy().
16+
-spec entropy(node(), statebox_clock:t_now()) -> entropy().
1617
entropy(Node, Now) ->
1718
erlang:phash2({Node, Now}).

0 commit comments

Comments
 (0)