slist


Nameslist JSON
Version 0.3.11 PyPI version JSON
download
home_pagehttps://github.com/thejaminator/slist
SummaryA typesafe list with more method chaining!
upload_time2024-10-27 12:07:43
maintainerNone
docs_urlNone
authorJames Chua
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements pytest pytest-asyncio typing-extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Slist
This is a drop in replacement for the built-in mutable python list

But with more post-fixed methods for chaining in a typesafe manner!!

Leverage the latest pyright features to spot errors during coding.

All these methods return a new list. They do not mutate the original list.

Not able to convince your colleagues to use immutable functional data structures? I understand.   
This library lets you still have the benefits of typesafe chaining methods while letting your colleagues have their mutable lists!





[![pypi](https://img.shields.io/pypi/v/slist.svg)](https://pypi.org/project/slist)
[![python](https://img.shields.io/pypi/pyversions/slist.svg)](https://pypi.org/project/slist)
[![Build Status](https://github.com/thejaminator/slist/actions/workflows/dev.yml/badge.svg)](https://github.com/thejaminator/slist/actions/workflows/dev.yml)

```
pip install slist
```


* GitHub: <https://github.com/thejaminator/slist>


## Quick Start
Easily spot errors when you call the wrong methods on your sequence with mypy.

```python
from slist import Slist

many_strings = Slist(["Lucy, Damion, Jon"])  # Slist[str]
many_strings.sum()  # Mypy errors with 'Invalid self argument'. You can't sum a sequence of strings!

many_nums = Slist([1, 1.2])
assert many_nums.sum() == 2.2  # ok!

class CannotSortMe:
    def __init__(self, value: int):
        self.value: int = value

stuff = Slist([CannotSortMe(value=1), CannotSortMe(value=1)])
stuff.sort_by(lambda x: x)  # Mypy errors with 'Cannot be "CannotSortMe"'. There isn't a way to sort by the class itself
stuff.sort_by(lambda x: x.value)  # ok! You can sort by the value

Slist([{"i am a dict": "value"}]).distinct_by(
    lambda x: x
)  # Mypy errors with 'Cannot be Dict[str, str]. You can't hash a dict itself
```

Slist provides methods to easily flatten and infer the types of your data.
```python
from slist import Slist, List
from typing import Optional

test_optional: Slist[Optional[int]] = Slist([-1, 0, 1]).map(
    lambda x: x if x >= 0 else None
)
# Mypy infers slist[int] correctly
test_flattened: Slist[int] = test_optional.flatten_option()


test_nested: Slist[List[str]] = Slist([["bob"], ["dylan", "chan"]])
# Mypy infers slist[str] correctly
test_flattened_str: Slist[str] = test_nested.flatten_list()
```

There are plenty more methods to explore!
```python
from slist import Slist

result = (
    Slist([1, 2, 3])
    .repeat_until_size_or_raise(20)
    .grouped(2)
    .map(lambda inner_list: inner_list[0] + inner_list[1] if inner_list.length == 2 else inner_list[0])
    .flatten_option()
    .distinct_by(lambda x: x)
    .map(str)
    .reversed()
    .mk_string(sep=",")
)
assert result == "5,4,3"
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thejaminator/slist",
    "name": "slist",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "James Chua",
    "author_email": "chuajamessh@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/26/a0e694ecbbddb7c2363865a5e106b967ac0f5c76c46e2c60d71f55f640dc/slist-0.3.11.tar.gz",
    "platform": null,
    "description": "# Slist\nThis is a drop in replacement for the built-in mutable python list\n\nBut with more post-fixed methods for chaining in a typesafe manner!!\n\nLeverage the latest pyright features to spot errors during coding.\n\nAll these methods return a new list. They do not mutate the original list.\n\nNot able to convince your colleagues to use immutable functional data structures? I understand.   \nThis library lets you still have the benefits of typesafe chaining methods while letting your colleagues have their mutable lists!\n\n\n\n\n\n[![pypi](https://img.shields.io/pypi/v/slist.svg)](https://pypi.org/project/slist)\n[![python](https://img.shields.io/pypi/pyversions/slist.svg)](https://pypi.org/project/slist)\n[![Build Status](https://github.com/thejaminator/slist/actions/workflows/dev.yml/badge.svg)](https://github.com/thejaminator/slist/actions/workflows/dev.yml)\n\n```\npip install slist\n```\n\n\n* GitHub: <https://github.com/thejaminator/slist>\n\n\n## Quick Start\nEasily spot errors when you call the wrong methods on your sequence with mypy.\n\n```python\nfrom slist import Slist\n\nmany_strings = Slist([\"Lucy, Damion, Jon\"])  # Slist[str]\nmany_strings.sum()  # Mypy errors with 'Invalid self argument'. You can't sum a sequence of strings!\n\nmany_nums = Slist([1, 1.2])\nassert many_nums.sum() == 2.2  # ok!\n\nclass CannotSortMe:\n    def __init__(self, value: int):\n        self.value: int = value\n\nstuff = Slist([CannotSortMe(value=1), CannotSortMe(value=1)])\nstuff.sort_by(lambda x: x)  # Mypy errors with 'Cannot be \"CannotSortMe\"'. There isn't a way to sort by the class itself\nstuff.sort_by(lambda x: x.value)  # ok! You can sort by the value\n\nSlist([{\"i am a dict\": \"value\"}]).distinct_by(\n    lambda x: x\n)  # Mypy errors with 'Cannot be Dict[str, str]. You can't hash a dict itself\n```\n\nSlist provides methods to easily flatten and infer the types of your data.\n```python\nfrom slist import Slist, List\nfrom typing import Optional\n\ntest_optional: Slist[Optional[int]] = Slist([-1, 0, 1]).map(\n    lambda x: x if x >= 0 else None\n)\n# Mypy infers slist[int] correctly\ntest_flattened: Slist[int] = test_optional.flatten_option()\n\n\ntest_nested: Slist[List[str]] = Slist([[\"bob\"], [\"dylan\", \"chan\"]])\n# Mypy infers slist[str] correctly\ntest_flattened_str: Slist[str] = test_nested.flatten_list()\n```\n\nThere are plenty more methods to explore!\n```python\nfrom slist import Slist\n\nresult = (\n    Slist([1, 2, 3])\n    .repeat_until_size_or_raise(20)\n    .grouped(2)\n    .map(lambda inner_list: inner_list[0] + inner_list[1] if inner_list.length == 2 else inner_list[0])\n    .flatten_option()\n    .distinct_by(lambda x: x)\n    .map(str)\n    .reversed()\n    .mk_string(sep=\",\")\n)\nassert result == \"5,4,3\"\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A typesafe list with more method chaining!",
    "version": "0.3.11",
    "project_urls": {
        "Homepage": "https://github.com/thejaminator/slist"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39a65844992e0abc645e8f8de3a3d680d8192409f662c3a74a50aa62e94a395c",
                "md5": "2ed22565aa3c6cf52ff75234a3281dd7",
                "sha256": "16dc774a46b035a1dc1fead451d9869734dcb9518a7092bd20f02edcc37723f4"
            },
            "downloads": -1,
            "filename": "slist-0.3.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ed22565aa3c6cf52ff75234a3281dd7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 10954,
            "upload_time": "2024-10-27T12:07:40",
            "upload_time_iso_8601": "2024-10-27T12:07:40.871741Z",
            "url": "https://files.pythonhosted.org/packages/39/a6/5844992e0abc645e8f8de3a3d680d8192409f662c3a74a50aa62e94a395c/slist-0.3.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e26a0e694ecbbddb7c2363865a5e106b967ac0f5c76c46e2c60d71f55f640dc",
                "md5": "4be2f479236c1d29c525a8cedb195a6f",
                "sha256": "e2c7b9c5a78bee1936c2092c4d19e6d5f6a54234251c8ab0eeb9d721b27d1ab7"
            },
            "downloads": -1,
            "filename": "slist-0.3.11.tar.gz",
            "has_sig": false,
            "md5_digest": "4be2f479236c1d29c525a8cedb195a6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 13895,
            "upload_time": "2024-10-27T12:07:43",
            "upload_time_iso_8601": "2024-10-27T12:07:43.338797Z",
            "url": "https://files.pythonhosted.org/packages/4e/26/a0e694ecbbddb7c2363865a5e106b967ac0f5c76c46e2c60d71f55f640dc/slist-0.3.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-27 12:07:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thejaminator",
    "github_project": "slist",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "7.2.0"
                ]
            ]
        },
        {
            "name": "pytest-asyncio",
            "specs": [
                [
                    "==",
                    "0.20.2"
                ]
            ]
        },
        {
            "name": "typing-extensions",
            "specs": []
        }
    ],
    "lcname": "slist"
}
        
Elapsed time: 0.58760s