I have been proferred this code snippet, which the author has not tested,
|> (fn l ->[?[, Enum.map(l, &([inspect(limit: :infinity), ?\n])), ?]] end).()
as part of a sequence of pipelined commands which converts data from a CSV file to a struct
using the DataMorph library, and outputs the result as a regular Elixir list for input into Elixir source - ie adding the surrounding brackets, and separating the elements of the list with commas.
This is what the sequence is meant to look like:
File.stream!('tmp.csv') \
|> DataMorph.structs_from_csv("open-register", :iso_country) \
|> (fn l ->[?[, Enum.map(l, &([inspect(limit: :infinity), ?\n])), ?]] end).()
|> (&File.write('output.txt',&1)).()
This is the error message when it is run in iex
:
* (CompileError) iex:55: invalid args for &, expected an expression in the format of &Mod.fun/arity, &local/arity or a capture containing at least one argument as &1, got: [inspect(limit: :infinity), 10]
(elixir) expanding macro: Kernel.|>/2
iex:55: (file)
Where is the fault in the snippet?
|> (fn l ->[?[, Enum.map(l, &([inspect(&1, limit: :infinity), ?\n])), ?]] end).()
– Dogbert|> (fn l ->[?[, Enum.map(l, &([inspect(&1, limit: :infinity), ?\n])) |> Enum.intersperse(?,), ?]] end).()
? Can you post the data and the expected output? – Dogbert,%StructType.TplParams{xxx
instead of the comma being appended to the previous line and the next one starting%StructType.TplParams{xxx
. pastebin.com/DCrpNDUh I think the correct way is use the,
in theinspect
formula, then use the\n
in theintersperse
function. I will give that a try. – vfclists",\n"
. I think that's what you want. – Dogbert