hassamullah

hassamullah

Cannot figure out NimbleCSV parser

In the first code snippet in the NimbleCSV Docs

NimbleCSV.define(MyParser, separator: “\t”, escape: “"”)

I don’t know where the MyParser variable comes form, kindly guide me

FYI, I’m new to elixir and still figuring out its ways

Most Liked

sodapopcan

sodapopcan

Hello and welcome to the forums!

NimbleCSV uses a pattern that isn’t too common amongst libraries so your confusion is certainly understandable. MyParser is not a variable but an atom. What that line is doing is actually defining a module called MyParser which you can then use like so: MyParser.parse_string("foo,bar"). You can call MyParser whatever you want.

kip

kip

ex_cldr Core Team

MyParser isn’t a variable. It’s a module name (module names are also atoms).

The docs for nimble_csv show that NimbleCsv.define/2 actually defines a new module, using the name you provide (in the example, its MyParser) that implements a parser using the options you pass.

Thats why you call MyParser.parse_string/1 to do the actual parsing of some CSV data. MyParser is just a regular Elixir module that just happened to be generated for you.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement