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
@Slicerator.from_class
class MyLazyLoader:
def __getitem__(self, i):
# this method will be wrapped by Slicerator, so that it accepts slices,
# lists of integers, or boolean masks. Code below will only be executed
# when an integer is used.
# load thing number i
return thing
def __len__(self):
# do stuff
return number_of_things
# 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
@Slicerator.from_class
class MyLazyLoader:
def __getitem__(self, i):
# this method will be wrapped by Slicerator, so that it accepts slices,
# lists of integers, or boolean masks. Code below will only be executed
# when an integer is used.
# load thing number i
return thing
def __len__(self):
# do stuff
return number_of_things
# 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.4.tar.gz
(21.4 kB
view details)
File details
Details for the file slicerator-0.9.4.tar.gz
.
File metadata
- Download URL: slicerator-0.9.4.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95529044d009d7e9d0b6b035c4d6892dc0ddc55136a7cf757131787b77e5a9b3 |
|
MD5 | 326841c72a596816198f088d2c430863 |
|
BLAKE2b-256 | 05ab3a94565f25237b2fd68e8efbc3d93ba1c4ee03beb18b5239ad1302081c57 |