Skip to content

Instantly share code, notes, and snippets.

@KOUCHANG
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KOUCHANG/ed31990f33cefb3c0431 to your computer and use it in GitHub Desktop.
Save KOUCHANG/ed31990f33cefb3c0431 to your computer and use it in GitHub Desktop.
Erlangの andalso は第2引数が boolean() じゃなくても良い ref: http://qiita.com/KOU_CHANG/items/a5c6bc7177976a8d8640
1> true andalso false.
false
2> true andalso ok.
ok
3> false orelse true.
true
4> false orelse ok.
ok
Expr1 orelse Expr2
Expr1 andalso Expr2
4> true or garbage.
** exception error: bad argument
in operator or/2
called as true or garbage
all(Pred, [Hd|Tail]) ->
Pred(Hd) andalso all(Pred, Tail);
all(_, []) ->
true.
get_value(Key, DefinedList) ->
case DefinedList =:= undefined orelse proplists:get_value(Key, DefinedList) of
{Key, Value} -> {ok, Value};
_ -> {error, not_match} %% NOT_MATCH_PROCESS
end.
get_value(_Key, undefined) ->
{error, not_match}; %% NOT_MATCH_PROCESS
get_value(Key, DefiendList) ->
case proplists:get_value(Key, DefinedList) of
{Key, Value} -> {ok, Value};
_ -> {error, not_match} %% NOT_MATCH_PROCESS
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment