-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//// # Parsing CSV | ||
//// | ||
//// The gsv package can be used to parse and render CSV on all targets. | ||
//// | ||
//// ## Dependencies | ||
//// | ||
//// - https://hex.pm/packages/gsv | ||
|
||
import gleam/dict | ||
import gleeunit/should | ||
import gsv | ||
|
||
pub fn main_test() { | ||
let csv = | ||
"name,colour,score | ||
Lucy,Pink,100 | ||
Nubi,Black,100 | ||
" | ||
|
||
// The `to_lists` function can be used to parse a CSV to a list of lists | ||
gsv.to_lists(csv) | ||
|> should.be_ok | ||
|> should.equal([ | ||
["name", "colour", "score"], | ||
["Lucy", "Pink", "100"], | ||
["Nubi", "Black", "100"], | ||
]) | ||
|
||
// It may be easier to work with your data as dicts. If so you can use the | ||
// `to_dicts` function. | ||
gsv.to_dicts(csv) | ||
|> should.be_ok | ||
|> should.equal([ | ||
dict.from_list([#("name", "Lucy"), #("colour", "Pink"), #("score", "100")]), | ||
dict.from_list([#("name", "Nubi"), #("colour", "Black"), #("score", "100")]), | ||
]) | ||
} |