You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
Easily spot errors when you call the wrong methods on your sequence with mypy.
fromslistimportSlistmany_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])
assertmany_nums.sum() ==2.2# ok!classCannotSortMe:
def__init__(self, value: int):
self.value: int=valuestuff=Slist([CannotSortMe(value=1), CannotSortMe(value=1)])
stuff.sort_by(lambdax: x) # Mypy errors with 'Cannot be "CannotSortMe"'. There isn't a way to sort by the class itselfstuff.sort_by(lambdax: x.value) # ok! You can sort by the valueSlist([{"i am a dict": "value"}]).distinct_by(
lambdax: 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.