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)
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)
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.0.tar.gz
(19.4 kB
view details)
File details
Details for the file slicerator-0.9.0.tar.gz
.
File metadata
- Download URL: slicerator-0.9.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644b40105e312b3b74223c8f484df8b1bd8b4584a937055a3b700dfc6be8fe86 |
|
MD5 | 3c34b1c7bba7ea48e2b573d9e982d7b9 |
|
BLAKE2b-256 | 75ba6e10d804611df86c0e5defc93b2cda6365072cd57e2ede4eec51634c2282 |