composable-indexes are implemented in TypeScript, and focuses on type safety. So, understanding what the types mean helps a lot in understanding how to use the library.
Nothing interesting here. A Collection holds values of type T. It does not
have much assumptions about T. The most important warning here is that most of
the functionality expect T to not change outside of the Collection methods.
So, it is recommended to use the Readonly<T> type here.
An Index represents a class of values that is kept up to date with the changes
happening in the underlying collection. At minimum it requires two type
parameters:
In: The type of the values that the index is going to be applied on.
Out: The type of the collection that this index belongs to.
The subclasses normally has methods that is used to query the index. For
example, the BTreeIndex inherits from Index, and exposes a range method.
An UnregisteredIndex is a description of an Index that is not yet
"registered" to a collection. You can pass an UnregisteredIndex to the
Collection's registerIndex method to get your Index.
UnregisteredIndex is also the place where you compose the indexes. Functions
like premap and group work on UnregisteredIndexes.
An AggregateIndex is a special kind of Index that is used to calculate
"aggregate values" from a collection. They don't return values from the
collection, so you don't see the Out type paremeter, but they always return a
single Value.
They can be constructed and composed more easily than ordinary Index'es.
composable-indexes
are implemented in TypeScript, and focuses on type safety. So, understanding what the types mean helps a lot in understanding how to use the library.Here are the main types:
Collection
Nothing interesting here. A
Collection
holds values of typeT
. It does not have much assumptions aboutT
. The most important warning here is that most of the functionality expectT
to not change outside of theCollection
methods. So, it is recommended to use theReadonly<T>
type here.Index
An
Index
represents a class of values that is kept up to date with the changes happening in the underlying collection. At minimum it requires two type parameters:In
: The type of the values that the index is going to be applied on.Out
: The type of the collection that this index belongs to.The subclasses normally has methods that is used to query the index. For example, the
BTreeIndex
inherits fromIndex
, and exposes arange
method.UnregisteredIndex
An
UnregisteredIndex
is a description of anIndex
that is not yet "registered" to a collection. You can pass anUnregisteredIndex
to theCollection
'sregisterIndex
method to get yourIndex
.UnregisteredIndex
is also the place where you compose the indexes. Functions likepremap
andgroup
work onUnregisteredIndex
es.AggregateIndex
An
AggregateIndex
is a special kind ofIndex
that is used to calculate "aggregate values" from a collection. They don't return values from the collection, so you don't see theOut
type paremeter, but they always return a singleValue
.They can be constructed and composed more easily than ordinary
Index
'es.