Add writer.stepwiseArrayCreation

This commit is contained in:
Zahary Karadjov 2022-06-17 20:16:28 +03:00
parent b9af0be99d
commit cc5038e0e2
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 7 additions and 4 deletions

View File

@ -103,9 +103,7 @@ template endRecordField*(w: var JsonWriter) =
endRecord(w)
w.state = AfterField
proc writeIterable*(w: var JsonWriter, collection: auto) =
mixin writeValue
iterator stepwiseArrayCreation*[C](w: var JsonWriter, collection: C): auto =
append '['
if w.hasPrettyOutput:
@ -122,7 +120,7 @@ proc writeIterable*(w: var JsonWriter, collection: auto) =
indent()
w.state = RecordExpected
w.writeValue(e)
yield e
first = false
if w.hasPrettyOutput:
@ -132,6 +130,11 @@ proc writeIterable*(w: var JsonWriter, collection: auto) =
append ']'
proc writeIterable*(w: var JsonWriter, collection: auto) =
mixin writeValue
for e in w.stepwiseArrayCreation(collection):
w.writeValue(e)
proc writeArray*[T](w: var JsonWriter, elements: openArray[T]) =
writeIterable(w, elements)