Array encoding for TOON format.
Handles encoding of vectors with support for:
Array encoding for TOON format.
Handles encoding of vectors with support for:
- Inline primitive arrays (key[N]: val1,val2,val3)
- Tabular arrays of objects (key[N]{col1,col2}: ...)
- Nested arrays of arrays(array-header length delimiter)Generates an array header with length information.
When delimiter is NOT comma, includes the delimiter in the header.
Parameters:
Returns: String like "[3]" or "[3|]" or "[3 ]"
Examples: (array-header 3 ",") ;=> "[3]" (array-header 3 "|") ;=> "[3|]" (array-header 3 "\t") ;=> "[3\t]"
Generates an array header with length information. When delimiter is NOT comma, includes the delimiter in the header. Parameters: - length: Number of elements in the array - delimiter: Delimiter character being used Returns: String like "[3]" or "[3|]" or "[3 ]" Examples: (array-header 3 ",") ;=> "[3]" (array-header 3 "|") ;=> "[3|]" (array-header 3 "\t") ;=> "[3\t]"
(encode arr delimiter depth writer)Encodes a vector to TOON format based on its contents.
Dispatch logic:
Parameters:
Returns: Updated LineWriter.
Encodes a vector to TOON format based on its contents. Dispatch logic: - Empty array: [] - Array of primitives: inline format - Array of objects: tabular format - Array of arrays: nested format Parameters: - array: Vector to encode - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
(extract-common-keys objects)Extracts common keys from an array of objects.
Returns keys that appear in all objects, in the order they appear in the first object.
Parameters:
Returns: Vector of common keys (as strings)
Examples: (extract-common-keys [{"a" 1 "b" 2} {"a" 3 "b" 4}]) ;=> ["a" "b"]
Extracts common keys from an array of objects.
Returns keys that appear in all objects, in the order they appear
in the first object.
Parameters:
- objects: Vector of maps
Returns:
Vector of common keys (as strings)
Examples:
(extract-common-keys [{"a" 1 "b" 2} {"a" 3 "b" 4}])
;=> ["a" "b"](inline values delimiter depth writer)Encodes an array of primitives as an inline comma-separated list.
Format (depth > 0): val1,val2,val3 Format (depth = 0): [N]: val1,val2,val3
Parameters:
Returns: Updated LineWriter with inline array content.
Examples: [1,2,3] at depth > 0 → "1,2,3" [1,2,3] at depth = 0 → "[3]: 1,2,3" ["a","b","c"] → "a,b,c"
Encodes an array of primitives as an inline comma-separated list. Format (depth > 0): val1,val2,val3 Format (depth = 0): [N]: val1,val2,val3 Parameters: - values: Vector of primitive values - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter with inline array content. Examples: [1,2,3] at depth > 0 → "1,2,3" [1,2,3] at depth = 0 → "[3]: 1,2,3" ["a","b","c"] → "a,b,c"
(mixed arr delimiter depth writer)Encodes a mixed array with header using list item markers.
Format: [N]:
Parameters:
Returns: Updated LineWriter.
Encodes a mixed array with header using list item markers. Format: [N]: - value1 - value2 Parameters: - array: Vector with mixed types - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
(mixed-items arr delimiter depth writer)Encodes mixed array items without a header.
Format (items only, no header):
Parameters:
Returns: Updated LineWriter.
Encodes mixed array items without a header. Format (items only, no header): - value1 - value2 - [N]: nested array Parameters: - array: Vector with mixed types - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
(object-as-list-item obj delimiter depth writer)Encodes an object as a list item with first key-value on hyphen line.
Format (single key):
Format (multiple keys):
Parameters:
Returns: Updated LineWriter.
Encodes an object as a list item with first key-value on hyphen line.
Format (single key):
- key: value
Format (multiple keys):
- key1: value1
key2: value2
key3: value3
Parameters:
- obj: Map to encode
- delimiter: Delimiter character
- depth: Current indentation depth
- writer: LineWriter instance
Returns:
Updated LineWriter.(of-arrays arrays delimiter depth writer)Encodes a nested array (array of arrays) with header using list format.
Format: N:
Parameters:
Returns: Updated LineWriter.
Encodes a nested array (array of arrays) with header using list format. Format: [N]: - [N]: val1,val2 - [N]: val3,val4 Parameters: - arrays: Vector of vectors - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
(of-arrays-items arrays delimiter depth writer)Encodes array of arrays items without a header.
Format (items only, no header):
Parameters:
Returns: Updated LineWriter.
Encodes array of arrays items without a header. Format (items only, no header): - [N]: val1,val2 - [N]: val3,val4 Parameters: - arrays: Vector of vectors - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
(tabular objects delimiter depth writer)Encodes an array of objects in tabular format.
Format: [N]{col1,col2}: val1,val2 val3,val4
Parameters:
Returns: Updated LineWriter.
Encodes an array of objects in tabular format.
Format:
[N]{col1,col2}:
val1,val2
val3,val4
Parameters:
- objects: Vector of maps with common keys
- delimiter: Delimiter character
- depth: Current indentation depth
- writer: LineWriter instance
Returns:
Updated LineWriter.(tabular-header cnt ks delimiter depth writer)Encodes the header for a tabular array.
Format (depth > 0): [N]{col1,col2,...}: Format (depth = 0): [N]{col1,col2,...}:
Parameters:
Returns: Updated LineWriter.
Encodes the header for a tabular array.
Format (depth > 0): [N]{col1,col2,...}:
Format (depth = 0): [N]{col1,col2,...}:
Parameters:
- count: Number of objects in array
- keys: Vector of column names
- delimiter: Delimiter character
- depth: Current indentation depth
- writer: LineWriter instance
Returns:
Updated LineWriter.(tabular-row obj ks delimiter depth writer)Encodes a single row in a tabular array.
Extracts values for the specified keys and encodes them.
Parameters:
Returns: Updated LineWriter.
Encodes a single row in a tabular array. Extracts values for the specified keys and encodes them. Parameters: - obj: Map representing one object - keys: Vector of keys to extract - delimiter: Delimiter character - depth: Current indentation depth - writer: LineWriter instance Returns: Updated LineWriter.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |