Permalink
Browse files

new is_statebox/1 function

  • Loading branch information...
1 parent d67ee3e commit 1f0304628215e5858ae2928c5c578b1254efce45 @etrepum etrepum committed Apr 24, 2011
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/statebox.erl
View
@@ -13,7 +13,7 @@
-module(statebox).
-export([new/2, modify/3, merge/1, expire/2, truncate/2,
new/1, modify/2,
- value/1, last_modified/1]).
+ value/1, last_modified/1, is_statebox/1]).
-record(statebox, {
value :: term(),
@@ -32,6 +32,14 @@
-export([dummy_mfa_4/4]).
-endif.
+%% @doc Return <code>true</code> if the argument is a statebox, <code>false</code>
+%% otherwise.
+-spec is_statebox(term()) -> boolean().
+is_statebox(#statebox{}) ->
+ true;
+is_statebox(_T) ->
+ false.
+
%% @doc Construct a statebox at <code>statebox_clock:timestamp()</code>
%% containing the result of <code>Constructor()</code>. This should
%% return an "empty" object of the desired type, such as
@@ -396,4 +404,13 @@ readme_ordsets_manual_test() ->
[a, b],
statebox:value(Resolved)).
+is_statebox_test() ->
+ ?assertEqual(
+ false,
+ is_statebox(not_a_statebox)),
+ ?assertEqual(
+ true,
+ is_statebox(new(fun () -> is_a_statebox end))),
+ ok.
+
-endif.

0 comments on commit 1f03046

Please sign in to comment.