ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - jimm/csvlixir: A CSV reading/writing application for Elixir.
A CSV reading/writing application for Elixir. Contribute to jimm/csvlixir development by creating an account on GitHub.
Visit Site

GitHub - jimm/csvlixir: A CSV reading/writing application for Elixir.

GitHub - jimm/csvlixir: A CSV reading/writing application for Elixir.

CSVLixir

A CSV reader/writer for Elixir. Operates on files or strings.

Installation

Add CSVLixir to your mix.exs dependencies:

def deps do
  [{:csvlixir, "~> 2.0.3"}]
end

Run mix deps.get. Done.

Reading

Files

To read CSV data from a file, use CSVLixir.read. It takes a path to a file and returns a Stream that generates and returns rows of CSV data.

CSVLixir.read("path/to/my.csv") |> Enum.to_list
#=> [["row", "one"], ["row", "two"]]

Strings

Parsing CSV data from a string returns a list of lists. Use CSVLixir.parse.

CSVLixir.parse("abc,def,ghi\n123,456,789")
#=> [["abc","def","ghi"],["123","456","789"]]

CSVLixir.parse(~s{abc,def,"gh"",""i"})
#=> [["abc", "def", "gh\",\"i"]]

CSVLixir.parse(File.read!("/tmp/foo.csv"))
#=> [["row", "one"], ["row", "two"]]

Writing

CSVLixir.write transforms a possibly lazy list of lists into a stream of CSV strings. Each generated string ends with a newline.

CSVLixir.write([["first", "row"], [123, 456]]) |> Enum.to_list
#=> ["first,row\n", "123,456\n"]

CSVLixir.write([["abc", "def", "gh\",\"i"], [123, 456, 789]])
|> Enum.each(&IO.write/1)
#=> abc,def,"gh"",""i"
#=> 123,456,789
#=> :ok

CSVLixir.write_row takes a single list and returns a single string.

CSVLixir.write_row(["a", "b", "c"])
#=> "a,b,c\n"

Writing to a file

Writing using streams:

f = File.open!("/tmp/csvlixir.csv", [:write])
1..3
|> Stream.map(&([&1, &1+1 ,&1+2]))
|> CSVLixir.write
|> Stream.each(&(IO.write(f, &1)))
|> Stream.run
File.close(f)

File.read!("/tmp/csvlixir.csv")
# => "1,2,3\n2,3,4\n3,4,5\n"

Writing a line at a time:

f = File.open!("/tmp/csvlixir.csv", [:write, :utf8])
IO.write(f, CSVLixir.write_row(["garçon", "waiter"]))
IO.write(f, CSVLixir.write_row(["résumé", "resume"]))
File.close(f)

File.read!("/tmp/csvlixir.csv")
# => "garçon,waiter\nrésumé,resume\n"

Don't forget to specify :utf8 when opening the file for writing if needed. (I often forget.)

Changes from 1.0

Adds reading from/writing to files. Removes support for char lists.

To Do

  • Allow different separator characters besides comma.
  • Handle headers. Return map instead of list, perhaps?

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory