Liking cljdoc? Tell your friends :D

com.vadelabs.toon.encode.arrays

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 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
raw docstring

array-headerclj/s

(array-header length delimiter)

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]"

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]"
sourceraw docstring

encodeclj/s

(encode arr delimiter depth writer)

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.

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.
sourceraw docstring

extract-common-keysclj/s

(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.

Uses set intersection for O(n×k) performance instead of O(n×k²).

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"]

Extracts common keys from an array of objects.

Returns keys that appear in all objects, in the order they appear
in the first object.

Uses set intersection for O(n×k) performance instead of O(n×k²).

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"]
sourceraw docstring

inlineclj/s

(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:

  • 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"

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"
sourceraw docstring

mixedclj/s

(mixed arr delimiter depth writer)

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.

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.
sourceraw docstring

mixed-itemsclj/s

(mixed-items arr delimiter depth writer)

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.

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.
sourceraw docstring

object-as-list-itemclj/s

(object-as-list-item obj delimiter depth writer)
(object-as-list-item obj delimiter depth writer encode-object-fn)

Encodes an object as a list item (v3.0 spec compliant).

For objects where first field is a tabular array:

  • key[N]{fields}: row1 row2 other-key: value

For objects with primitive first field:

  • key: value other-key: other-value

For empty objects:

Parameters:

  • obj: Map to encode
  • delimiter: Delimiter character
  • depth: Current indentation depth
  • writer: LineWriter instance
  • encode-object-fn: (optional) Function to encode nested objects

Returns: Updated LineWriter.

Encodes an object as a list item (v3.0 spec compliant).

For objects where first field is a tabular array:
  - key[N]{fields}:
      row1
      row2
    other-key: value

For objects with primitive first field:
  - key: value
    other-key: other-value

For empty objects:
  -

Parameters:
  - obj: Map to encode
  - delimiter: Delimiter character
  - depth: Current indentation depth
  - writer: LineWriter instance
  - encode-object-fn: (optional) Function to encode nested objects

Returns:
  Updated LineWriter.
sourceraw docstring

of-arraysclj/s

(of-arrays arrays delimiter depth writer)

Encodes a nested array (array of arrays) with header using list format.

Format: N:

Parameters:

  • arrays: Vector of vectors
  • delimiter: Delimiter character
  • depth: Current indentation depth
  • writer: LineWriter instance

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.
sourceraw docstring

of-arrays-itemsclj/s

(of-arrays-items arrays delimiter depth writer)

Encodes array of arrays items without a header.

Format (items only, no header):

Parameters:

  • arrays: Vector of vectors
  • delimiter: Delimiter character
  • depth: Current indentation depth
  • writer: LineWriter instance

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.
sourceraw docstring

tabularclj/s

(tabular objects delimiter depth writer)

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.

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.
sourceraw docstring

tabular-headerclj/s

(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:

  • count: Number of objects in array
  • keys: Vector of column names
  • delimiter: Delimiter character
  • depth: Current indentation depth
  • writer: LineWriter instance

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.
sourceraw docstring

tabular-rowclj/s

(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:

  • obj: Map representing one object
  • keys: Vector of keys to extract
  • delimiter: Delimiter character
  • depth: Current indentation depth
  • writer: LineWriter instance

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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close