normalize_sequence#
- skrough.algorithms.meta.helpers.normalize_sequence(items: Optional[Union[T, Sequence[T]]], optional: bool) List[T][source]#
Normalize a sequence of items to a list.
The function normalizes input items to a list form. The input
itemscan be given as a single element, a sequence orNone(optionally) and a list is returned that corresponds to the given input, i.e., respectively, a list containing the single element, the input list itself or an empty list (optionally).The function is instrumented by
optionalargument which controls the function’s behavior forNonepassed asitemsargument. Foroptional is Truethe function will return an empty list, while foroptional is Falsethe function will raise aValueErrorexception.- Parameters:
items – Items that should be normalized to a list.
optional – Controls the function’s behavior for
Nonepassed asitems, i.e., foroptional is Truethe function will return an empty list, otherwise it will raise aValueErrorexception.
- Raises:
ValueError – When
optional is TrueandNoneis given asitems.- Returns:
A list that corresponds to the input
items.