Collection
when_exactly.Collection
A Collection is an ordered, deduplicated set of Intervals.
Collections automatically sort their values and remove duplicates. They provide iteration, indexing, slicing, and membership testing operations. Collections are the base class for concrete types like Days, Months, Years, etc.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
list[when_exactly.core.collection.CollectionT]
|
A sorted list of unique intervals in this collection. |
Example
>>> import when_exactly as wnx
>>> # Days is a subclass of Collection
>>> days = wnx.Days([
... wnx.Day(2025, 1, 1),
... wnx.Day(2025, 1, 3),
... wnx.Day(2025, 1, 2),
... wnx.Day(2025, 1, 1), # duplicate, will be removed
... ])
>>> len(days)
3
>>> days[0]
Day(2025, 1, 1)
>>> wnx.Day(2025, 1, 2) in days
True
values
property
Get the sorted list of unique intervals in this collection.
Returns:
| Type | Description |
|---|---|
list[when_exactly.core.collection.CollectionT]
|
A sorted list of intervals. |
__init__(values)
Initialize a Collection with the given intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
typing.Iterable[when_exactly.core.collection.CollectionT]
|
An iterable of intervals. Duplicates will be removed and the intervals will be sorted. |
required |