A lazy-loading, fancy-sliceable iterable.
Project description
Slicerator
==========
a lazy-loading, fancy-slicable iterable
Think of it like a generator that is "reusable" and has a length.
[![build status](https://travis-ci.org/soft-matter/slicerator.png?branch=master)](https://travis-ci.org/soft-matter/slicerator)
Installation
------------
On any platform, use pip or conda.
`pip install slicerator`
or
`conda install -c soft-matter slicerator`
Example
-------
```
from slicerator import Slicerator
class MyLazyLoader:
def __getitem__(self, i):
# If a specific item is requested, load it and return it.
# Otherwise, return a lazy-loading Slicerator.
if isinstance(i, int):
# load thing number i
return thing
else:
return Slicerator(self, range(len(self)), len(self))[i]
def __len__(self):
# do stuff
return number_of_things
def __iter__(self):
return iter(self[:])
# Demo:
>>> a = MyLazyLoader()
>>> s1 = a[::2] # no data is loaded yet
>>> s2 = s1[1:] # no data is loaded yet
>>> some_data = s2[0]
```
==========
a lazy-loading, fancy-slicable iterable
Think of it like a generator that is "reusable" and has a length.
[![build status](https://travis-ci.org/soft-matter/slicerator.png?branch=master)](https://travis-ci.org/soft-matter/slicerator)
Installation
------------
On any platform, use pip or conda.
`pip install slicerator`
or
`conda install -c soft-matter slicerator`
Example
-------
```
from slicerator import Slicerator
class MyLazyLoader:
def __getitem__(self, i):
# If a specific item is requested, load it and return it.
# Otherwise, return a lazy-loading Slicerator.
if isinstance(i, int):
# load thing number i
return thing
else:
return Slicerator(self, range(len(self)), len(self))[i]
def __len__(self):
# do stuff
return number_of_things
def __iter__(self):
return iter(self[:])
# Demo:
>>> a = MyLazyLoader()
>>> s1 = a[::2] # no data is loaded yet
>>> s2 = s1[1:] # no data is loaded yet
>>> some_data = s2[0]
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
slicerator-0.9.3.tar.gz
(21.5 kB
view details)
File details
Details for the file slicerator-0.9.3.tar.gz
.
File metadata
- Download URL: slicerator-0.9.3.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a5b60cfc843807f25b658f945aa43642fe0b304be885956176022d3f4be314f |
|
MD5 | 8abd69d45b138ce499a248002b5a2709 |
|
BLAKE2b-256 | e3e8ece5a508a052ffc1c1c9619d2bd4575d3fa37162eee4e310e0eb046ace49 |