<div dir="ltr">Hi, Gian.<div><br></div><div>You might be interested in reading [1], first shown to the Erlang world in [2] (there's more info. in the archives, if you search).</div><div><br></div><div>FYI, it is being hacked away, at this very moment, in SpawnFest 2021: <a href="https://github.com/spawnfest/eep49ers">https://github.com/spawnfest/eep49ers</a>.</div><div><br></div><div>Cheers.</div><div><br></div><div>- Paulo F. Oliveira</div><div><br></div><div>[1] <a href="https://github.com/erlang/eep/blob/master/eeps/eep-0049.md">https://github.com/erlang/eep/blob/master/eeps/eep-0049.md</a></div><div>[2] <a href="http://erlang.org/pipermail/eeps/2018-September/000554.html">http://erlang.org/pipermail/eeps/2018-September/000554.html</a><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 19 Sept 2021 at 14:37, Gian Lorenzo Meocci <<a href="mailto:glmeocci@gmail.com">glmeocci@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I think that there isn't a generic solution for this problem. It’s time to introduce the 'with' operator in Erlang 😂</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il Dom 19 Set 2021, 09:06 Attila Rajmund Nohl <<a href="mailto:attila.r.nohl@gmail.com" target="_blank">attila.r.nohl@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello!<br>
<br>
One way (I haven't actually tried to compile this, but hopefully you<br>
get the idea):<br>
<br>
get_nas_from_conf() -><br>
try<br>
{ok, Server} = get_radius_host(),<br>
{ok, Port} = get_radius_port(),<br>
{ok, Secret} = get_radius_secret(),<br>
{Server, Port, Secret};<br>
catch<br>
error:{badmatch, E} -><br>
E<br>
end.<br>
<br>
Of course, if the badmatch comes from the get_* functions, this<br>
construct might catch that too, but you might be able to ensure this<br>
doesn't happen.<br>
<br>
Gian Lorenzo Meocci <<a href="mailto:glmeocci@gmail.com" rel="noreferrer" target="_blank">glmeocci@gmail.com</a>> ezt írta (időpont: 2021.<br>
szept. 18., Szo, 22:50):<br>
><br>
> Hi,<br>
> I have a function like this:<br>
><br>
> get_nas_from_conf() -><br>
> case get_radius_host() of<br>
> {ok, Server} -><br>
> case get_radius_port() of<br>
> {ok, Port} -><br>
> case get_radius_secret() of<br>
> {ok, Secret} -><br>
> {Server, Port, Secret};<br>
> E -> E<br>
> end;<br>
> E -><br>
> E<br>
> end;<br>
> E -><br>
> E<br>
> end.<br>
><br>
> Which is the best way to write this kind of function?<br>
><br>
> I'd like to have a with operator like in Elixir, to rewrite my function in this way:<br>
><br>
> get_nas_from_conf() -><br>
> with {ok, Server} <- get_radius_host(),<br>
> {ok, Port} = get_radius_port(),<br>
> {ok, Secret} = get_radius_secret() -><br>
> {Server, Port, Secret};<br>
> catch<br>
> {error, _Reason} = E -><br>
> E<br>
> end.<br>
><br>
> Any suggestion?<br>
><br>
> --<br>
> GL<br>
> <a href="https://www.meocci.it" rel="noreferrer noreferrer" target="_blank">https://www.meocci.it</a><br>
</blockquote></div>
</blockquote></div>