Skip to main content

Collection iterator over classes

Project description

pycollection

pycollection is an amazing library that allows you to iterate through a list, but it returns a transformed item. It has a lot of methods to interact with the collection. It works similar than laravel collections. Current version is 1.0.2.

Basic usage

class NumberCollection(Collection):

    def item(self, item):
        return Number(item)


class Number:

    def __init__(self, item):
        self._item = item

    def value(self):
        return self._item

    def squared(self):
        return self._item * self._item


numbers = NumberCollection([1,2,3,4,5])


for number in numbers:
    print(number.squared())

# output
# > 1
# > 4
# > 9
# > 16
# > 25

As you can see, it allows for an easy-to-read syntax for navigating between lists and their elements, since you can provide new functionality to both.

Available methods

methods
count
json
find
where
item
first
append
items

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

pycollection-1.0.2.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

pycollection-1.0.2-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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