<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<div class="moz-cite-prefix">I have used (from
<a class="moz-txt-link-freetext" href="https://github.com/CloudI/CloudI/blob/a43715b71facafc9a8ad7c7fe55c7383773c22df/src/lib/cloudi_core/src/cloudi_core_i_configuration.erl#L6022-L6039">https://github.com/CloudI/CloudI/blob/a43715b71facafc9a8ad7c7fe55c7383773c22df/src/lib/cloudi_core/src/cloudi_core_i_configuration.erl#L6022-L6039</a>):<br>
<div>
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(220,220,170)">-type eval_value() :: number() | atom() | list().
-spec eval(L :: list({eval_value(),
fun((eval_value()) -> {ok, any()} | {error, any()})})) ->
tuple().
eval(L) ->
eval(L, []).
eval([], Output) ->
erlang:list_to_tuple([ok | lists:reverse(Output)]);
eval([{Value, F} | L], Output)
when is_number(Value) orelse is_atom(Value) orelse is_list(Value) ->
case F(Value) of
{ok, ValueNew} ->
eval(L, [ValueNew | Output]);
{error, _} = Error ->
Error
end.
</span></div></div></div>
</div>
<br>
However, the eval function above is assuming each function in the
2-tuple list is taking a value it is paired with as input. The
return tuple has the 'ok' atom to show it is a success case. For
your situation, you wouldn't need an input value for your function
values (so only a list of function values would be necessary).<br>
<br>
Best Regards,<br>
Michael<br>
<br>
On 9/18/21 10:14 AM, Gian Lorenzo Meocci wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAAPjnHWhWhbOSquTCKjKJWhef-nGzEcRVGAyrRagxsrj_E9fiw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<div dir="ltr">
<div>Hi,</div>
<div>I have a function like this:</div>
<div><br>
</div>
<div>
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(220,220,170)">get_nas_from_conf</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_host</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_port</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_secret</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> {</span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">};</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">.</span></div></div></div>
</div>
<div><br>
</div>
<div>Which is the best way to write this kind of function?</div>
<div><br>
</div>
<div>I'd like to have a with operator like in Elixir, to rewrite
my function in this way:</div>
<div><br>
</div>
<div>
<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(220,220,170)">get_nas_from_conf</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> <span style="color:rgb(212,212,212)"></span><span style="color:rgb(197,134,192)">with</span> {ok, </span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">} <- </span><span style="color:rgb(220,220,170)">get_radius_host</span><span style="color:rgb(212,212,212)">(),</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(220,220,170)">get_radius_port</span><span style="color:rgb(212,212,212)">(),</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(220,220,170)">get_radius_secret</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> {</span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">};</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">catch</span></div><div><span style="color:rgb(212,212,212)"> {error, </span><span style="color:rgb(156,220,254)">_Reason</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">.</span></div></div>
</div>
<div><br>
</div>
<div>Any suggestion?</div>
<div><br>
</div>
<div>-- <br>
<div dir="ltr" data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>GL<br>
<a href="https://meox.github.io" target="_blank"
moz-do-not-send="true">https://www.meocci.it</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>