Last active
December 25, 2015 17:09
-
-
Save ToJans/7011003 to your computer and use it in GitHub Desktop.
What I love about Erlang: no "if" statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @doc Register a new identity. | |
-spec register_identity(identifier()) -> succeeded(). | |
%% @end | |
register_identity(Id) -> | |
F = fun () -> | |
Identity = get_identity(Id), | |
{_, true} = {already_registered, Identity =/= not_found}, | |
identity_registered(Id) | |
end, | |
transact(F). | |
%% @doc Enable an identity. | |
-spec enable_identity(identifier()) -> succeeded(). | |
%% @end | |
enable_identity(Id) -> | |
F = fun () -> | |
Identity = get_identity(Id), | |
{_, true} = {unknown_identity, Identity == not_found}, | |
{_, true} = {already_enabled, Identity#identities.enabled == true} , | |
identity_enabled(Identity) | |
end, | |
transact(F). | |
%% @doc Disable an identity. | |
-spec disable_identity(identifier()) -> succeeded(). | |
%% @end | |
disable_identity(Id) -> | |
F = fun() -> | |
Identity = get_identity(Id), | |
{_, true} = {unknown_identity, Identity == not_found}, | |
{_, true} = {already_disabled, Identity#identities.enabled == false} , | |
identity_disabled(Identity) | |
end, | |
transact(F). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment