struct

Data structure manipulation tools.

License:
  • Apache-2.0
Source:

Methods

(inner) access(input, pathopt, defopt) → {OutputType|undefined}

Apply path to an object o. Return element reachable through that path or def value.

Example:

access({ a: { b: [10, { c: 42 }] } }, ["a", "b", 1, "c"])  ===  42
Source:
Parameters:
Name Type Attributes Default Description
input InputType
path <optional>
[]
def <optional>
Returns:
Type:
OutputType | undefined

(inner) assign(base, ext) → {Object}

Safe version of standard JavaScript Object.assign(); Throws when base and ext have conflicting keys - prevents accidental overwrite.

Source:
Parameters:
Name Type Description
base Object
ext Object
Returns:
Type:
Object

base

(inner) clone(o) → {JSAnyArrObj}

Do the deep-copy of any JavaScript object that doesn't contain functions.

Source:
Parameters:
Name Type Description
o JSAnyArrObj
Returns:
Type:
JSAnyArrObj

(inner) dfs(tree, f, childrenopt) → {any}

Depth-first search. Executes certain operation f on each tree node in reduce-like fashion, accumulating intermediate results.

Source:
See:
Parameters:
Name Type Attributes Description
tree Object

Tree-like structure.

f function

Function to be executed on each node. Its signature is as follows: function (accs, node, path, position), where:

  • accs - array of accumulated results, for each subtree of current node
  • node - reference to current node
  • path - current node is reachable by applying struct.access to tree and path
  • position - position of currently processed node in an array of children (current node is "position-th" child of its parent)

children function <optional>

Function that should accept node and return array of n tuples. In each tuple first element should be the n-th child of the node and second element should be the path leading from the node to the n-th child. If there is no children under given node then returned array should be empty.

Returns:
Type:
any

Accumulated result for all subtree nodes.

(inner) dict(entries) → {Object}

Construct Object from the result of Object.entries() call.

entries = [[k1, v1], ..., [kn, vn]]

Imitates Python's dict().

Source:
Parameters:
Name Type Description
entries Array.<Array>
Returns:
Type:
Object

(inner) hashAccessor() → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs to enumerate on any javascript object.

Source:
See:
Returns:
Type:
function

(inner) isBasicData(c) → {Boolean}

Check if value is of BasicData type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean

(inner) isBasicDataOrUndefined(c) → {Boolean|undefined}

Check if value is of BasicData of undefined type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean | undefined

(inner) keyAccessor(…path) → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs if your tree-like structure contains children organized as arrays.

E.g. if a node is defined as follows:

node = { val: "something", props: { num: 14, ch: [node1, node2] } }

then keyAccessor should be defined in this way:

keyAccessor("props", "ch")

keyAccessor called without arguments (keyAccessor()) returns hashAccessor.

Source:
See:
Parameters:
Name Type Attributes Description
path Number | String <repeatable>

A path leading from the node to the children array.

Returns:
Type:
function

(inner) objectMap(o, f)

Map (iteration) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • kv - current [key, value] array,

f should return [key, value] array.

Source:
Parameters:
Name Type Description
o

Object

f

Function

Returns:

Mapped object

(inner) objectReduce(o, f, init)

Reduce (fold) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • acc - accumulated value,
    • kv - current [key, value] array,
  • init - accumulated value initializer,

f should return value of the same type as init.

Source:
Parameters:
Name Type Description
o

Object

f

Function

init

T

Returns:

T

(inner) rewrite(o, path, v) → {Data}

Rewrite part of an object (first argument) reachable through passed path (second argument) with provided value (third argument). Creates new object with new data and references to all unchanged parts of the old object. This function implements copy-on-write semantics.

Source:
Parameters:
Name Type Description
o Data
path DataIndex
v Data
Returns:
Type:
Data

(inner) swap(o) → {JSAnyObj}

When o == { a: "b", c: "d" } then swap(o) == { b: "a", d: "c" }.

Source:
Parameters:
Name Type Description
o JSAnyObj
Returns:
Type:
JSAnyObj

Struct - type declarations.

License:
  • Apache-2.0
Source:

Methods

(inner) access(input, pathopt, defopt) → {OutputType|undefined}

Apply path to an object o. Return element reachable through that path or def value.

Example:

access({ a: { b: [10, { c: 42 }] } }, ["a", "b", 1, "c"])  ===  42
Source:
Parameters:
Name Type Attributes Default Description
input InputType
path <optional>
[]
def <optional>
Returns:
Type:
OutputType | undefined

(inner) assign(base, ext) → {Object}

Safe version of standard JavaScript Object.assign(); Throws when base and ext have conflicting keys - prevents accidental overwrite.

Source:
Parameters:
Name Type Description
base Object
ext Object
Returns:
Type:
Object

base

(inner) clone(o) → {JSAnyArrObj}

Do the deep-copy of any JavaScript object that doesn't contain functions.

Source:
Parameters:
Name Type Description
o JSAnyArrObj
Returns:
Type:
JSAnyArrObj

(inner) dfs(tree, f, childrenopt) → {any}

Depth-first search. Executes certain operation f on each tree node in reduce-like fashion, accumulating intermediate results.

Source:
See:
Parameters:
Name Type Attributes Description
tree Object

Tree-like structure.

f function

Function to be executed on each node. Its signature is as follows: function (accs, node, path, position), where:

  • accs - array of accumulated results, for each subtree of current node
  • node - reference to current node
  • path - current node is reachable by applying struct.access to tree and path
  • position - position of currently processed node in an array of children (current node is "position-th" child of its parent)

children function <optional>

Function that should accept node and return array of n tuples. In each tuple first element should be the n-th child of the node and second element should be the path leading from the node to the n-th child. If there is no children under given node then returned array should be empty.

Returns:
Type:
any

Accumulated result for all subtree nodes.

(inner) dict(entries) → {Object}

Construct Object from the result of Object.entries() call.

entries = [[k1, v1], ..., [kn, vn]]

Imitates Python's dict().

Source:
Parameters:
Name Type Description
entries Array.<Array>
Returns:
Type:
Object

(inner) hashAccessor() → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs to enumerate on any javascript object.

Source:
See:
Returns:
Type:
function

(inner) isBasicData(c) → {Boolean}

Check if value is of BasicData type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean

(inner) isBasicDataOrUndefined(c) → {Boolean|undefined}

Check if value is of BasicData of undefined type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean | undefined

(inner) keyAccessor(…path) → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs if your tree-like structure contains children organized as arrays.

E.g. if a node is defined as follows:

node = { val: "something", props: { num: 14, ch: [node1, node2] } }

then keyAccessor should be defined in this way:

keyAccessor("props", "ch")

keyAccessor called without arguments (keyAccessor()) returns hashAccessor.

Source:
See:
Parameters:
Name Type Attributes Description
path Number | String <repeatable>

A path leading from the node to the children array.

Returns:
Type:
function

(inner) objectMap(o, f)

Map (iteration) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • kv - current [key, value] array,

f should return [key, value] array.

Source:
Parameters:
Name Type Description
o

Object

f

Function

Returns:

Mapped object

(inner) objectReduce(o, f, init)

Reduce (fold) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • acc - accumulated value,
    • kv - current [key, value] array,
  • init - accumulated value initializer,

f should return value of the same type as init.

Source:
Parameters:
Name Type Description
o

Object

f

Function

init

T

Returns:

T

(inner) rewrite(o, path, v) → {Data}

Rewrite part of an object (first argument) reachable through passed path (second argument) with provided value (third argument). Creates new object with new data and references to all unchanged parts of the old object. This function implements copy-on-write semantics.

Source:
Parameters:
Name Type Description
o Data
path DataIndex
v Data
Returns:
Type:
Data

(inner) swap(o) → {JSAnyObj}

When o == { a: "b", c: "d" } then swap(o) == { b: "a", d: "c" }.

Source:
Parameters:
Name Type Description
o JSAnyObj
Returns:
Type:
JSAnyObj

Data structure manipulation tools.

License:
  • Apache-2.0
Source:

Methods

(inner) access(input, pathopt, defopt) → {OutputType|undefined}

Apply path to an object o. Return element reachable through that path or def value.

Example:

access({ a: { b: [10, { c: 42 }] } }, ["a", "b", 1, "c"])  ===  42
Source:
Parameters:
Name Type Attributes Default Description
input InputType
path <optional>
[]
def <optional>
Returns:
Type:
OutputType | undefined

(inner) assign(base, ext) → {Object}

Safe version of standard JavaScript Object.assign(); Throws when base and ext have conflicting keys - prevents accidental overwrite.

Source:
Parameters:
Name Type Description
base Object
ext Object
Returns:
Type:
Object

base

(inner) clone(o) → {JSAnyArrObj}

Do the deep-copy of any JavaScript object that doesn't contain functions.

Source:
Parameters:
Name Type Description
o JSAnyArrObj
Returns:
Type:
JSAnyArrObj

(inner) dfs(tree, f, childrenopt) → {any}

Depth-first search. Executes certain operation f on each tree node in reduce-like fashion, accumulating intermediate results.

Source:
See:
Parameters:
Name Type Attributes Description
tree Object

Tree-like structure.

f function

Function to be executed on each node. Its signature is as follows: function (accs, node, path, position), where:

  • accs - array of accumulated results, for each subtree of current node
  • node - reference to current node
  • path - current node is reachable by applying struct.access to tree and path
  • position - position of currently processed node in an array of children (current node is "position-th" child of its parent)

children function <optional>

Function that should accept node and return array of n tuples. In each tuple first element should be the n-th child of the node and second element should be the path leading from the node to the n-th child. If there is no children under given node then returned array should be empty.

Returns:
Type:
any

Accumulated result for all subtree nodes.

(inner) dict(entries) → {Object}

Construct Object from the result of Object.entries() call.

entries = [[k1, v1], ..., [kn, vn]]

Imitates Python's dict().

Source:
Parameters:
Name Type Description
entries Array.<Array>
Returns:
Type:
Object

(inner) hashAccessor() → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs to enumerate on any javascript object.

Source:
See:
Returns:
Type:
function

(inner) isBasicData(c) → {Boolean}

Check if value is of BasicData type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean

(inner) isBasicDataOrUndefined(c) → {Boolean|undefined}

Check if value is of BasicData of undefined type. Non recursive check.

Source:
Parameters:
Name Type Description
c unknown
Returns:
Type:
Boolean | undefined

(inner) keyAccessor(…path) → {function}

Construct function appropriate to use as the children argument in the struct.dfs function. Use it with struct.dfs if your tree-like structure contains children organized as arrays.

E.g. if a node is defined as follows:

node = { val: "something", props: { num: 14, ch: [node1, node2] } }

then keyAccessor should be defined in this way:

keyAccessor("props", "ch")

keyAccessor called without arguments (keyAccessor()) returns hashAccessor.

Source:
See:
Parameters:
Name Type Attributes Description
path Number | String <repeatable>

A path leading from the node to the children array.

Returns:
Type:
function

(inner) objectMap(o, f)

Map (iteration) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • kv - current [key, value] array,

f should return [key, value] array.

Source:
Parameters:
Name Type Description
o

Object

f

Function

Returns:

Mapped object

(inner) objectReduce(o, f, init)

Reduce (fold) on objects - shallow.

  • o - Object to enumerate on.
  • f - Function to call on each key, params:
    • this - bound to the enumerated object,
    • acc - accumulated value,
    • kv - current [key, value] array,
  • init - accumulated value initializer,

f should return value of the same type as init.

Source:
Parameters:
Name Type Description
o

Object

f

Function

init

T

Returns:

T

(inner) rewrite(o, path, v) → {Data}

Rewrite part of an object (first argument) reachable through passed path (second argument) with provided value (third argument). Creates new object with new data and references to all unchanged parts of the old object. This function implements copy-on-write semantics.

Source:
Parameters:
Name Type Description
o Data
path DataIndex
v Data
Returns:
Type:
Data

(inner) swap(o) → {JSAnyObj}

When o == { a: "b", c: "d" } then swap(o) == { b: "a", d: "c" }.

Source:
Parameters:
Name Type Description
o JSAnyObj
Returns:
Type:
JSAnyObj