From d4ab2f4e550de70e7d743eb835a9126c4352a781 Mon Sep 17 00:00:00 2001 From: Zozi Date: Wed, 7 Aug 2024 14:39:35 -0600 Subject: [PATCH] chore: Update Linq class __repr__ method to include iterable elements --- README.md | 10 ++++++++++ linq/linq.py | 14 ++++++++++++++ setup.py | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddc3ff2..253ca45 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,16 @@ pip install linq-tool ## Usage Examples +You might create a Linq instance and iterate throughout the object + +```python +linq = Linq([1, 2, 3]) +for item in linq: + print(item) # 1 +``` + +The object is an iterable, if you need to use it as list, you need to invoke the `to_list` method + ### Select ```python diff --git a/linq/linq.py b/linq/linq.py index c0639fd..af214b5 100644 --- a/linq/linq.py +++ b/linq/linq.py @@ -430,3 +430,17 @@ def __iter__(self) -> Iterator[T]: 3 """ return iter(self.iterable) + + def __repr__(self) -> str: + """ + Returns a string representation of the Linq object. + + Returns: + str: A string representation of the Linq object. + + Example: + >>> linq = Linq([1, 2, 3]) + >>> repr(linq) + 'Linq([1, 2, 3])' + """ + return f"Linq({list(self.iterable)})" diff --git a/setup.py b/setup.py index beec1f5..8cbec88 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ long_description_content_type='text/markdown', author='Zozimo Fernandez', author_email='zozi.fer96@gmail.com', - url='https://github.com/tu_usuario/linq-tool', + url='https://github.com/Zozi96/linq-tool', packages=find_packages(), classifiers=[ 'Programming Language :: Python :: 3',