Utility methods

Part of: tag_Utilities

Each Sqimitive instance inherits a bunch of functions from your utility library in addition to standard ones (tag_Utilities) – those used to sort, filter, transform, count, locate, cook, boil, slice up and serve nest’ed children as regular objects and arrays. For example:

sqim.filter(child => child.get('enabled'))
// Instead of:
_.filter(sqim.slice(), child => child.get('enabled'))

These functions are generally portable but with subtle differences in availability and behaviour between NoDash no@, Underscore un: and LoDash – check the no:COMPATIBILITY table for details.

For portability avoid using shortcut iterator syntax – it’s only supported in Underscore (un:iteratee), not in NoDash, LoDash or in standard Array/Object methods. Notable exceptions are pick()/omit(): in Underscore and NoDash the iterator may be a function or a list of property names, in LoDash – list only.

If doing several transformations one after another consider _() which allows chaining.

from unordered

Attention: JavaScript objects are unordered, as explained in the description of Ordered.

For this reason some methods are only available when mixing-in Sqimitive\Ordered which guarantees iteration order.

The iterator argument may be followed by call context (cx) which defaults to the sqimitive if omitted.

Methods working with children keys (nested())

iterator = function (Sqimitive child, string parentKey)
Example: sqim.keys() → _.keys(sqim.nested()).

Methods available for Sqimitive\Base subclasses:

Methods working on children positions (slice())

iterator = function (Sqimitive child, int index)
Example: sqim.sample() → _.sample(sqim.slice()).

from unordered

Attention: JavaScript objects are unordered, as explained in the description of Ordered.

If Sqimitive\Ordered is not used, index is an arbitrary number sequential in this particular call to the utility method; sqim.filter((c, i) => sqim.slice(i, 1)) may produce undefined behaviour. For Ordered, index is stable and can be given to at() or slice().

Attention: forEach() and other methods here work with child indexes, not keys! Obtain keys by _parentKey if the collection is _owning, or by findKey(), or do _.each(col.nested(), (sqim, key) => ...). For Ordered, can also use at(index).key.

Methods available for Sqimitive\Base subclasses:

Methods available if mixed-in Sqimitive\Ordered:

Defined in: HELP.chem, lines 1414-1523 (110 lines)