[erlang-questions] Erlang and Akka, The Sequel
Fred Hebert
mononcqc@REDACTED
Wed Apr 1 20:23:57 CEST 2015
On 03/31, Youngkin, Rich wrote:
>> try
>> {ok, Cs} = adventure:collect_coins(),
>> Res = lists:flatmap(fun(Coins) ->
>> {ok, Val} = adventure:buy_treasure(Coins),
>> Val
>> end, Cs),
>> of
>> SuccessValue ->
>> %% Do something like continue to next challenge
>> catch
>> Type:Reason ->
>> %% Do something like maybe repeat the previous challenge
>> end.
>> ...
>> try
>> lists:flatmap(fun(Coins) -> adventure:buy_treasure(Coins) end,
>> adventure:collect_coins())
>> of
>> SuccessValue -> % Keep going
>> catch
>> _:_ -> % alt path
>> end
>>
>
>I don't see a difference between the previous 2 Erlang implementations. Can
>you elaborate?
>
One of them matches on `{ok, Value}' to cause a failure, which makes the
assumption 'bad' cases are returned as `undefined' or `{ok, Error}'. In
the latter case it is expected that the called code raises exceptions
when something goes wrong.
They're two fundamentally different approaches to designing your
interface. They can, of course, be mixed together depending on the
importance (or frequency) of the error.
Regards,
Fred.
More information about the erlang-questions
mailing list