I have experience in JavaScript and I am used to callbacks functions:
function myFun(arg1, arg2, successCB, failCB) {
var sum = arg1 + arg2;
if (sum > tooHigh) {
failCB("too high!");
} else {
otherFun(sum, arg1, successCB, failCB);
}
}
I can write the same code in Erlang:
my_fun(Arg1, Arg2, SuccessCB, FailCB) ->
case Arg1 + Arg2 of
Sum when Sum > ?TOO_HIGH ->
FailCB(too_high);
Sum ->
other_fun(Sum, Arg1, SuccessCB, FailCB)
end.
I find this approach reasonable from my experience, but I feel like I will need to do a lot of this in my code, so, apparently, there is a better way to manage these true/false/whatever scenarios.
Is this typical Erlang code? Is there some other way that I should be doing this?