Skip to content

Commit

Permalink
patch 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Sep 26, 2024
1 parent 2f35591 commit 2fab9de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/gsv.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ pub fn from_dicts(

let rows =
list.map(input, fn(row) {
row
|> dict.to_list
|> list.sort(fn(lhs, rhs) {
string.compare(pair.first(lhs), pair.first(rhs))
list.fold(headers, [], fn(acc, h) {
case dict.get(row, h) {
Ok(v) -> [v, ..acc]
Error(Nil) -> ["", ..acc]
}
})
|> list.map(pair.second)
})
|> list.map(list.reverse)

from_lists([headers, ..rows], separator, line_ending)
}
Expand Down
2 changes: 1 addition & 1 deletion test/gsv_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,6 @@ pub fn dicts_with_missing_values_test() {
]
gsv.from_dicts(data, ",", gsv.Unix)
|> should.equal(
"colour,name,score,youtube\nPink,Lucy,100\nIsaac,99,@IsaacHarrisHolt",
"colour,name,score,youtube\nPink,Lucy,100,\n,Isaac,99,@IsaacHarrisHolt",
)
}

0 comments on commit 2fab9de

Please sign in to comment.