Objects implementing this interface define how they are handled as containers
by Lenses. Implementations are automatically polyfilled for
Object, Array, and Map. Implementations can be polyfilled to support
Immutable by require
-ing or import
ing
module:natural-lenses/immutable or calling
module:natural-lenses#polyfillImmutable.
The names of the methods of this interface are defined by symbols from module:natural-lenses.
Methods
[at_maybe](key) → {Maybe.<*>}
The key passed to this method will be from the keys of a Lens -- the kind
of value that should be passed for a conceptual "indexing" of the container.
For Object, this is a string property name. For Array, this is an integer index,
where negative values count backward from the end of the Array. For Map, the
argument may be any type, which is passed to Map.prototype.has
and possibly
Map.prototype.get
as a key value.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key/index whose value to retrieve from this container |
Returns:
A Maybe for the value associated with key in this
- Type
- Maybe.<*>
[clone](opDesc) → {*}
The intent of the method is to clone the container with some kind of alteration -- either a key/index set to the given value in the clone, or a key/index deleted from the clone.
If the operation description passed contains a set
property,
the value of that property should be an Array where element 0 is a key or
index into the container and element 1 is the value to set (cf. arguments
to Map.prototype.set
).
If the operation description passed contains a spliceOut
property,
the value of that property should be a key or index to delete from the
container. Where possible, the result should be to leave the container
in a state where container[at_maybe](key)
returns {}
(a Nothing).
This is specifically a problem for immutable.List,
which offers only a dense presentation of elements: every non-negative index
less than size
is a valid and "contained" entry. The implementation provided
by this library for implementing this method on
immutable.List sets the value of the entry
in the clone to undefined
.
In the provided implemenation for Array, negative indexes are interpreted
counting backward from the end of the Array, as with Array.prototype.slice
.
Symbol.species
is honored for determining the constructor used for the
clone; Object is a special case that defaults to Object if Symbol.species
is not present.
In a future major version, it is likely that the call interface for this
method will change to function({key: *} | {key: *, just: *}): *
, where
presence of just
(and its associated value) in the argument represents a
"setting" of key in the result, and absence of just
represents omission
of key from the result.
Parameters:
Name | Type | Description |
---|---|---|
opDesc |
Object |
Returns:
A modified clone of this
- Type
- *