Problem no. 1 why my additional question in (FunctionClauseError) no function clause matching in Access.get/3 was deleted by moderator whereas it was asking a question about the answer to the original quesiton
Problem no. 2 I am trying to comprehend why: the original and (NOT working) answer
{:ok, decode_csv} =
File.stream!('users_departs.csv')
|> Stream.drop(1)
|> CSV.decode(headers: [:name, :title, :departments])
raises:
== Compilation error in file lib/data_dictionary.ex ==
** (MatchError) no match of right hand side value: #Function<62.51129937/2 in Stream.transform/3>
...
The documentation is extremely vague on this and I am unlucky enough to have just upgraded to the 2.2.1 version of the CSV.
I am quite puzzled not knowing how the heck process the return value of the CSV.decode...
With my best wishes Tomasz
As clearly stated in the documentation, CSV.decode/2
returns a stream . Until you have it terminated, it's a stream. That said, what you need is to ensure you a) terminate it somehow, eg by converting to the list with Enum.to_list/1
, and b) you properly handle the return values, which are basically tuples {:ok, values}
or {:error, description}
.
For the trivial case, when you are fine with raising on errors, just use the banged version CSV.decode!/2
which returns a streamed list or raises if it fails to parse any row.
'users_departs.csv'
|> File.stream!()
|> Stream.drop(1)
|> CSV.decode!(headers: [:name, :title, :departments])
|> Enum.to_list() # ESSENTIAL!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.