Skip to content

soft-matter/slicerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8669c26 · Apr 8, 2022
Feb 3, 2022
May 11, 2018
Feb 3, 2022
Feb 3, 2022
Feb 3, 2022
Feb 3, 2022
Jun 7, 2017
Jul 12, 2015
Jul 30, 2015
Jun 7, 2017
Mar 2, 2019
Feb 3, 2022
Jun 7, 2017
Apr 7, 2022
May 11, 2018
Feb 3, 2022

Repository files navigation

Slicerator

a lazy-loading, fancy-slicable iterable

Think of it like a generator that is "reusable" and has a length.

Please see the documentation for examples and an API reference.

build status Documentation Status

Installation

On any platform, use pip or conda.

pip install slicerator

or

conda install -c conda-forge 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]