Skip to content

Period.range as a sequence #308

Open
@ghost

Description

#129 made period a generator, which is better than a list. An even more flexible option might be to make it a lazy sequence, like python3's range(), so it's indexable

range(4)[0]

but not exhaustible

r = range(4); list(r) == list(r)

Current behavior:

In [19]: a = pendulum.now('UTC')                                                                                                                                                             

In [20]: b = pendulum.now('UTC')                                                                                                                                                             

In [21]: period = a - b                                                                                                                                                                      

In [22]: seconds = period.range('seconds')                                                                                                                                                   

In [23]: seconds                                                                                                                                                                             
Out[23]: <generator object Period.range at 0x7f4e8d676d58>

In [24]: seconds[0]                       
TypeError: 'generator' object is not subscriptable

In [25]: range(1, 5)[0]                                                                                                                                                                      
Out[25]: 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions