logic - how to generate list of records using list of lists data in erlang -
i have list of lists itemlistdata = [[1,"abc","def",30],[2,"axn","foo",23],[3,"bde","fo1",21],..]
, form list of records using record item{itemno, name, description, quantity}
. items list length varying. best way create new list of records using itemlistdata
.
@graymalkin's answer involves lot of copying through use of ++
binary operator. 1 should prefer list comprehensions here:
make_records(records) -> [#item{'#'=no, name=name, descr=descr, qty=qty} || [no,name,descr,qty] <- records].
edit: use function thusly: (in shell)
1> rd(item, {'#', name, descr, qty}). 2> itemlistdata = [[1,"abc","def",30],[2,"axn","foo",23],[3,"bde","fo1",21]]. 3> some_module:make_records(itemlistdata).
Comments
Post a Comment