3 ms·
I think macintux is referring to something like this: get_exactly_n_or_crash(N) -> {N, Data} = get_data(N). Suppose get_data will get N or less pieces (
by Jtsummers 5y ago
I think macintux is referring to something like this:
get_exactly_n_or_crash(N) ->
{N, Data} = get_data(N).
Suppose get_data will get N or less pieces (if N pieces of data aren't available) of data and return, as a tuple, both the amount of data obtained and the data. The above assignment is actually part of Erlang's pattern matching, the second use of N (on the LHS of the =) is not actually an assignment, it's a check. If get_data returned less than N pieces of data, the program would crash (which you can catch and respond to) at that point.