Perhaps a hidden but yet powerful usage of a combinations of collection is underrated in many software solutions, where search operations are performed by iterating collection items one by one, which might hurt performance in some cases.
Also, imagine that you would want to get an ordered array of persons ordered by their age:
Above approaches are fine when we work with tiny collections, but once you need to work with collections of 1000, 10,000 or more items, these would turn into a performance bottleneck.
Also, taking the whole index object, just imagine that we own a person id and
we want to know if the whole person is older than 30. We wouldn’t need to get
the person from index.persons and check if person.age > 30, but it would be
as easy as (read the comments to get further information):
Highlights of this approach
It’s applicable to most modern programming languages and even NoSQL databases like Redis.
Objects or data is retrieved very fast even with large collections because they’re not iterated anymore to search or extract objects or data.
Some boolean checks become easier and more readable.
As a con, some indexing logic should be implemented and objects or data should be indexed carefully.
Did you find some problem on this design pattern, or do you want to improve it?
Go to our GitHub repository and open an issue, and let's talk about it!