How do I convert [<<"a">>, <<"b">>, <<"c">>]
to ["a", "b", "c"]
?
In Erlang, Lists are created by enclosing the values in square brackets.
You can use length() to find the length of a list, and can use list comprehensions to filter your list. num(L) -> length([X || X <- L, X < 1]). Working example: % list counter program -module(listcounter).
Binaries store data in a much more space efficient manner than in lists or tuples, and the runtime system is optimized for the efficient input and output of binaries. Binaries are written and printed as sequences of integers or strings, enclosed in double less than and greater than brackets.
Strings are enclosed in double quotes ("), but is not a data type in Erlang.
[binary_to_list(X) || X <- [<<"a">>, <<"b">>, <<"c">>]].
or more elaborate
BinList = [<<"a">>, <<"b">>, <<"c">>], NormalList = [binary_to_list(X) || X <- BinList], NormalList.
Or, using lists:map/2:
lists:map(fun erlang:binary_to_list/1, [<<"a">>, <<"b">>, <<"c">>]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With