Skip to content

Commit 2fab9de

Browse files
committed
patch 2
1 parent 2f35591 commit 2fab9de

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/gsv.gleam

+6-5
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ pub fn from_dicts(
134134

135135
let rows =
136136
list.map(input, fn(row) {
137-
row
138-
|> dict.to_list
139-
|> list.sort(fn(lhs, rhs) {
140-
string.compare(pair.first(lhs), pair.first(rhs))
137+
list.fold(headers, [], fn(acc, h) {
138+
case dict.get(row, h) {
139+
Ok(v) -> [v, ..acc]
140+
Error(Nil) -> ["", ..acc]
141+
}
141142
})
142-
|> list.map(pair.second)
143143
})
144+
|> list.map(list.reverse)
144145

145146
from_lists([headers, ..rows], separator, line_ending)
146147
}

test/gsv_test.gleam

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,6 @@ pub fn dicts_with_missing_values_test() {
231231
]
232232
gsv.from_dicts(data, ",", gsv.Unix)
233233
|> should.equal(
234-
"colour,name,score,youtube\nPink,Lucy,100\nIsaac,99,@IsaacHarrisHolt",
234+
"colour,name,score,youtube\nPink,Lucy,100,\n,Isaac,99,@IsaacHarrisHolt",
235235
)
236236
}

0 commit comments

Comments
 (0)