speasy.core.typing module
- speasy.core.typing.all_of_type(collection: Sequence, expected_type: Type) bool[source]
Returns true only if the type of all elements in given collection is expected_type
- Parameters:
- collection: Sequence
Any iterable object
- expected_type: Type
the type you expect to match
- Returns:
- bool
True only if the type of all elements in given collection is expected_type
Examples
>>> all_of_type([1,2,3], int) True
>>> all_of_type([1,2,3.], int) False
- speasy.core.typing.is_collection(value: Any) bool[source]
- Parameters:
- valueAny
- Returns:
- bool
True if given value is collection like object but not a string
- speasy.core.typing.listify(obj: Any) List[source]
Wraps inside a list anything that is not a list. Useful in for loops when you can’t be sure the object you want to iterate is a list.
- Parameters:
- obj: Any
Any object or list
- Returns:
- list
list(obj) if obj is not a list
Examples
>>> for i in listify(1): ... print(i) ... 1
>>> for i in listify([1,2,3]): ... print(i) ... 1 2 3