Skip to main content

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]
```

Project details


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)

Uploaded Source

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

Hashes for slicerator-0.9.0.tar.gz
Algorithm Hash digest
SHA256 644b40105e312b3b74223c8f484df8b1bd8b4584a937055a3b700dfc6be8fe86
MD5 3c34b1c7bba7ea48e2b573d9e982d7b9
BLAKE2b-256 75ba6e10d804611df86c0e5defc93b2cda6365072cd57e2ede4eec51634c2282

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page