LINQ with full typing support (WIP).
Project description
types-linq
This is an attempt to implement linq methods seen in .NET (link). Currently WIP.
To run the test cases, install pytest
, and then invoke it under the current directory:
$ pytest
To install it on the computer, do
$ pip install .
# or
$ python setup.py install
The usage is simple if you know about the interfaces in .NET as this library provides almost the exact methods:
from dataclasses import dataclass
from types_linq import Enumerable as en
@dataclass
class PetOwner:
name: str
pets: List[str]
pet_owners = [
PetOwner(name='Higa', pets=['Scruffy', 'Sam']),
PetOwner(name='Ashkenazi', pets=['Walker', 'Sugar']),
PetOwner(name='Price', pets=['Scratches', 'Diesel']),
PetOwner(name='Hines', pets=['Dusty']),
]
query = en(pet_owners) \
.select_many(
lambda pet_owner: pet_owner.pets,
lambda pet_owner, pet_name: (pet_owner, pet_name),
) \
.where(lambda owner_and_pet: owner_and_pet[1].startswith('S')) \
.select(lambda owner_and_pet: {
'owner': owner_and_pet[0].name, 'pet': owner_and_pet[1],
}
)
for obj in query:
print(obj)
# output:
# {'owner': 'Higa', 'pet': 'Scruffy'}
# {'owner': 'Higa', 'pet': 'Sam'}
# {'owner': 'Ashkenazi', 'pet': 'Sugar'}
# {'owner': 'Price', 'pet': 'Scratches'}
This example is taken from the .NET doc.
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
types-linq-0.0.1.tar.gz
(5.1 kB
view hashes)