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.
Instalation
pip install pycollection
Basic usage
from pycollection import collection
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 | action |
|---|---|
| count() | gets the number of total elements in the list |
| json() | jsonifies the list |
| find(callaback: Callable) | returns the first item that match with the callback |
| where(callback: Callable) | returns a new collection that meets the callback |
| item(element) | transforms each of the elements of the list when it is iterated over it |
| first() | gets the first item of the list |
| append(element) | add a new element to the list |
| items() | retrieves the collection list |
| random() | retrieves a random item from the collection |
| get(index:int) | retrieves an element according to the given index |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycollection-1.0.6.tar.gz.
File metadata
- Download URL: pycollection-1.0.6.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.10.1 urllib3/1.26.6 tqdm/4.64.1 importlib-metadata/4.6.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a24e9881a5f286848ee6ea6bf73e5c9170dc45bffab8a891a9d15f6d086cbbb
|
|
| MD5 |
fe51fccb1e53f67f5544806fbcc10547
|
|
| BLAKE2b-256 |
d0a223c64470ec0be53f29af6d8c623cd550f2abdd3009fe69a3e80d3edd0a21
|
File details
Details for the file pycollection-1.0.6-py3-none-any.whl.
File metadata
- Download URL: pycollection-1.0.6-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.10.1 urllib3/1.26.6 tqdm/4.64.1 importlib-metadata/4.6.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
984469c821964cce24561215feb7f1542cc59aa7f15f198153cd22809ba5fbf8
|
|
| MD5 |
52a49bac44c3fe1dbf2bd8b29e8f4e5e
|
|
| BLAKE2b-256 |
7da6c164e3b2870cc577a6515781b50e8bbc09f443d4af51c3a08783992779e5
|