IndexableMixin

IndexableMixin

Methods

(inner) at(index, pickLensopt) → {Lens}

Build a lens through a specific index

Source:

There are several ways to call this method, with different argument patterns:

  1. datumLens.at(index)
  2. datumLens.at(index, itemSlotPicker)
  3. datumLens.at(index, itemSlotLens)

Pattern 1 creates a lens to the index-th item of the indexable object targeted by this lens.

Pattern 2 creates an optic (a lens where possible) targeting a slot within the index-th item of the indexable targeted by this lens, where the slot within the item is selected by the result of itemSlotPicker. itemSlotPicker is called with the item datum plan for the target of this lens if one is specified within the datum plan.

Pattern 3 is similar to pattern 2, just directly passing a lens (or lens-like object) rather than a function that returns one.

Parameters:
Name Type Attributes Description
index number

Index into the Array targeted by this lens on which to focus

pickLens function | Lens <optional>

A lens to a slot within the selected item or a Function returning such a lens given the item plan

Returns:

A lens (or at least some optic) to the item or a slot within the item

Type
Lens

(inner) flatMapInside(subject, subItemsForItem, optionsopt) → {T}

Clone the subject with the target of this lens altered by flatMapping items

Source:

This method allows the creation of a clone of subject where the target of this lens has been replaced with an iterable composed of zero or more values for each item in the equivalent slot in subject.

When subItemsForItem is called, it is provided an item from the target of this lens, the index of the item within the target iterable of this lens and, if available, the datum plan for that item. The Function passed for subItemsForItem MUST return an iterable of values to be substituted in place of the item it received in the returned clone.

If reduce is supplied, it is applied to an iterable chaining all the result items returned by all calls to subItemsForItem. The value returned by reduce must be iterable.

Parameters:
Name Type Attributes Description
subject T

The input structured data

subItemsForItem function

Callback providing the iterable of items (possibly empty) to replace each item

options Object <optional>
Properties
Name Type Attributes Description
orThrow <optional>

OptionalThrow

reduce function <optional>

Callback to reduce the sequence of accumulated items

Returns:

A minimally changed clone of subject with the transformed value in this slot

Type
T

(inner) length(subject) → {number}

Get the length of the targeted Array (or Array-like)

Source:
Parameters:
Name Type Description
subject

The input structured data

Returns:

The length of the targeted Array, or undefined

Type
number

(inner) mapInside(subject, …manipulator) → {T}

Clone the subject with the target of this lens altered by mapping items

Source:

There are several ways to call this method, with different types of manipulators:

  1. datumLens.mapInside(subject, itemXform)
  2. datumLens.mapInside(subject, itemSlotPicker, itemSlotXform)
  3. datumLens.mapInside(subject, itemSlotLens, itemSlotXform)

Pattern 1 applies a transformation function (itemXform) to each item of the iterable selected by this lens as the clone of subject is made.

Pattern 2 is for applying a change within each item of the iterable targeted by this lens as a clone is made, selecting the slot within each item by returning a lens from itemSlotPicker. itemSlotPicker is called with the item datum plan for the targeted iterable if one exists in the datum plan.

Pattern 3 is similar to pattern 2, just directly passing a lens (or something that knows how to xformInClone) rather than a function that returns one.

The itemXform function in pattern 1 is called with the item value, its index within the iterable and, if specified, the item datum plan for each item of the target iterable of this lens.

The itemSlotXform function in patterns 2 and 3 is called with the slot value and the index of the current item within the target iterable of this lens.

Parameters:
Name Type Attributes Description
subject T

The input structured data

manipulator * <repeatable>

See description

Returns:

A minimally changed clone of subject with the transformed value in this slot

Type
T