Permalink
Browse files

Cleaned up type specs for dialyzer #4

  • Loading branch information...
etrepum committed Sep 15, 2013
1 parent 38be26d commit 00239981c258581a4a4fb8d2f05e8022387d1bc3
Showing with 21 additions and 10 deletions.
  1. +2 −3 .travis.yml
  2. +5 −0 CHANGES.md
  3. +1 −1 src/statebox.app.src
  4. +4 −2 src/statebox.erl
  5. +7 −3 src/statebox_clock.erl
  6. +2 −1 src/statebox_identity.erl
View
@@ -2,6 +2,5 @@ language: erlang
notifications:
email: false
otp_release:
- - R14B03
- - R14B02
- - R14B01
+ - R15B03
+ - R16B01
View
@@ -1,3 +1,8 @@
+Version 0.2.3 released 2013-09-15
+
+* Cleaned up type specs for dialyzer
+ https://github.com/mochi/statebox/issues/4
+
Version 0.2.2 released 2011-06-14
* Updated README
View
@@ -1,7 +1,7 @@
{application, statebox,
[
{description, "Erlang state \"monad\" with merge/conflict-resolution capabilities. Useful for Riak."},
- {vsn, "0.2.2"},
+ {vsn, "0.2.3"},
{registered, []},
{applications, [
kernel,
View
@@ -22,11 +22,12 @@
last_modified :: timestamp()}).
-opaque statebox() :: #statebox{}.
-type event() :: {timestamp(), op()}.
--type timestamp() :: integer().
+-type timestamp() :: statebox_clock:timestamp().
-type timedelta() :: integer().
-type basic_op() :: {module(), atom(), [term()]} |
{fun((...) -> statebox()), [term()]}.
-type op() :: basic_op() | [op()].
+-export_type([statebox/0, event/0, timestamp/0, timedelta/0, basic_op/0, op/0]).
%% Used in a test, must be done before function definitions.
-ifdef(TEST).
@@ -35,7 +36,7 @@
%% @doc Return <code>true</code> if the argument is a statebox, <code>false</code>
%% otherwise.
--spec is_statebox(term()) -> boolean().
+-spec is_statebox(statebox() | term()) -> boolean().
is_statebox(#statebox{}) ->
true;
is_statebox(_T) ->
@@ -46,6 +47,7 @@ is_statebox(_T) ->
%% return an "empty" object of the desired type, such as
%% <code>fun gb_trees:empty/0</code>.
%% @equiv new(timestamp(), Constructor)
+-spec new(fun(() -> term())) -> statebox().
new(Constructor) ->
new(statebox_clock:timestamp(), Constructor).
View
@@ -4,21 +4,25 @@
-module(statebox_clock).
-export([timestamp/0, now_to_msec/1, now/0]).
+-type t_now() :: {integer(), integer(), integer()}.
+-type timestamp() :: integer().
+-export_type([t_now/0, timestamp/0]).
+
-define(KILO, 1000).
-define(MEGA, 1000000).
%% @doc Current UNIX epoch timestamp in integer milliseconds.
%% Equivalient to <code>now_to_msec(os:timestamp())</code>.
--spec timestamp() -> integer().
+-spec timestamp() -> timestamp().
timestamp() ->
now_to_msec(os:timestamp()).
%% @doc Converts given time of now() format to UNIX epoch timestamp in
%% integer milliseconds.
--spec now_to_msec(calendar:t_now()) -> integer().
+-spec now_to_msec(t_now()) -> timestamp().
now_to_msec({MegaSecs, Secs, MicroSecs}) ->
trunc(((MegaSecs * ?MEGA) + Secs + (MicroSecs / ?MEGA)) * ?KILO).
--spec now() -> calendar:t_now().
+-spec now() -> t_now().
now() ->
erlang:now().
@@ -4,6 +4,7 @@
-export([entropy/2, entropy/0]).
-type entropy() :: 1..4294967296.
+-export_type([entropy/0]).
%% @equiv entropy(node(), statebox_clock:now())
-spec entropy() -> entropy().
@@ -12,6 +13,6 @@ entropy() ->
%% @doc Return an integer that can be expected to be reasonably unique
%% at a given msec timestamp.
--spec entropy(node(), calendar:t_now()) -> entropy().
+-spec entropy(node(), statebox_clock:t_now()) -> entropy().
entropy(Node, Now) ->
erlang:phash2({Node, Now}).

0 comments on commit 0023998

Please sign in to comment.