The Problem
There have been a number of times when using Erlang that I’ve found myself concatenating a list of binaries and strings. I usually resort to manual conversions one way or the other… and I think you’ll agree they’re both pretty ugly.
|
|
There’s a helpful lists:concat function that quickly converts a list of elements to a single string. Unfortunately, the list of allowed types doesn’t include binaries.
|
|
The Solution
Here’s a small snippet with some eunit tests that’ll convert binaries to strings, run them through the lists:concat
function, then return the binary or string you asked for.
|
|
Usage
To use it, just pass a list of any element types that lists:concat
would normally allow, as well as binaries.
|
|
If you find a better way to do this, let me know!