Authors: Serge Aleynikov (saleyn@gmail.com).
Conditional expression functions This module exports a parse transform and implements several condition-checking functions.
When using this as a parse transform, include{parse_transform,iif}
option.
In that case the following code transforms will be done:
iif(A, B, C) -> begin V = A, if V -> B; true -> C end end iif(A,B,C,D) -> case A of B -> C; _ -> D end nvl(A,B) -> case A of false -> B; undefined -> B; [] -> B; _ -> A end nvl(A,B,C) -> case A of false -> B; undefined -> B; [] -> B; _ -> C endFor debugging the AST of the resulting transform, use
iif_debug
command-line option:
erlc -Diif_debug=1 ... % Prints AST before the transform erlc -Diif_debug=2 ... % Prints AST after the transform erlc -Diif_debug[=3] ... % Prints AST before/after the transform
format_ne/3 | Format if first argument is not empty. |
ife/2 | Return Value if first argument is one of: [] , false , undefined . |
ife/3 | Return Empty if first argument is one of: [] , false , undefined . |
ifne/2 | Return Value if first argument is not one of: [] , false , undefined . |
ifne/3 | Return NotEmpty if first argument is not one of: [] , false , undefined . |
iif/3 | Return True if first argument is true or return False if
the first argument is one of: [] , false , undefined . |
iif/4 | Return True if first two arguments match. |
nvl/2 | |
parse_transform/2 | Parse transform to be used by providing {parse_transform, iif} option. |
format_ne(True, Fmt, Args) -> any()
Format if first argument is not empty
ife(Test, Value) -> any()
Return Value
if first argument is one of: []
, false
, undefined
.
Otherwise return the value of the first argument.
ife(Value, Empty, NotEmpty) -> any()
Return Empty
if first argument is one of: []
, false
, undefined
.
Otherwise, if NotEmpty
is fun()
, evaluate it, or if it's fun(Arg)
evaluate it with Value
argument.
ifne(Test, Value) -> any()
Return Value
if first argument is not one of: []
, false
, undefined
.
Otherwise, if Value
is fun()
, evaluate it, or if it's fun(Arg)
evaluate it with Test
argument.
If not empty
ifne(Value, NotEmpty, Empty) -> any()
Return NotEmpty
if first argument is not one of: []
, false
, undefined
.
Otherwise, if NotEmpty
is fun()
, evaluate it, or if it's fun(Arg)
evaluate it with Value
argument.
iif(X1, True, False) -> any()
Return True
if first argument is true
or return False
if
the first argument is one of: []
, false
, undefined
.
iif(Value, Other, True, False) -> any()
Return True
if first two arguments match
nvl(Value, IfNull) -> any()
parse_transform(Ast, Opts) -> any()
Parse transform to be used by providing {parse_transform, iif}
option.
Opts
are compiler options passed from command line. E.g.:
erlc -Diif_debug=N ... -> Opts = [{d,debug,N}|_] erlc -Diif_debug ... -> Opts = [{d,debug}|_]
Generated by EDoc