I have a simple record structure consisting of a header (H) and a list of the data lines (D) 1:N. All header lines must start with a digit. All data lines have a leading whitespace. There also might be some empty lines (E) in between that must be ignored.
L = [H, D, D, E, H, D, E, H, D, D, D].
I would like to create a list of records:
-record(posting,{header,data}).
using list comprehension. Whats the best way to do it?
You should do something like this:
Anyway I think that straightforward Erlang version doesn’t seems too complicated and should be little bit faster.
Edit: If you have to add better row classification or parsing, adding new function is better because it improves readability.
You can use it like this:
Tail recursive native Erlang solution:
I think that there is no reason use tail recursion from performance point of view:
… and many many other variants.