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

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics 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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement