Re: Binary String pattern matching
Håkan Huss <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CA+fT_JcWn2SrMfqOj5y9WNVCmNb0ecHCt5iEX12aDFAuAMUOnw@mail.gmail.com> |
For lists there is no way. For binaries it is actually possible using
guards:
currency_to_credits({cur, V}, Acc) when binary_part(V, {byte_size(V), -3})
== <<"CHF">>,
binary_part(V, {0, byte_size(V) -
3}) >= <<"1000">>,
binary_part(V, {0, byte_size(V) -
3}) =< <<"10000">> ->
{chf, Acc + binary_to_integer(binary:part(V, {0, byte_size(V) - 3}))};
...
However, I would argue that it's much more readable if you split the binary
in currency_to_credits and pass on the parts to a helper function that
handles the logic.
Regards,
/Håkan