Skip to content

Commit 2f35591

Browse files
committed
patch from_dicts
1 parent d1843bc commit 2f35591

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
## v2.0.1 - 26 September 2024
6+
- Patch to consider all headers in from_dicts.
7+
58
## v2.0.0 - 24 September 2024
69
- Now there are four public functions, `to_lists`, `to_dicts`, `from_lists` and `from_dicts`.
710

gleam.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "gsv"
2-
version = "2.0.0"
2+
version = "2.0.1"
33
gleam = ">= 0.32.0"
44
description = "A simple csv parser and generator written in gleam "
55

src/gsv.gleam

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ pub fn from_dicts(
124124
) -> String {
125125
case input {
126126
[] -> ""
127-
[first_row, ..] -> {
127+
_ -> {
128128
let headers =
129-
first_row
130-
|> dict.to_list
131-
|> list.map(pair.first)
129+
input
130+
|> list.map(dict.keys)
131+
|> list.flatten
132+
|> list.unique
132133
|> list.sort(string.compare)
133134

134135
let rows =

test/gsv_test.gleam

+15
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,18 @@ pub fn dicts_with_empty_values_test() {
219219
dict.from_list([#("age", "27"), #("name", "Austin")]),
220220
])
221221
}
222+
223+
pub fn dicts_with_missing_values_test() {
224+
let data = [
225+
dict.from_list([#("name", "Lucy"), #("score", "100"), #("colour", "Pink")]),
226+
dict.from_list([
227+
#("name", "Isaac"),
228+
#("youtube", "@IsaacHarrisHolt"),
229+
#("score", "99"),
230+
]),
231+
]
232+
gsv.from_dicts(data, ",", gsv.Unix)
233+
|> should.equal(
234+
"colour,name,score,youtube\nPink,Lucy,100\nIsaac,99,@IsaacHarrisHolt",
235+
)
236+
}

0 commit comments

Comments
 (0)