openmnglab.util.iterables.ensure_sequence#

openmnglab.util.iterables.ensure_sequence(inp: ~typing.Iterable[~openmnglab.util.iterables.T] | ~openmnglab.util.iterables.T | None, type: ~typing.Type[~openmnglab.util.iterables.T], sequence_constructor: ~typing.Callable[[~typing.Iterable[~openmnglab.util.iterables.T]], ~typing.Sequence[~openmnglab.util.iterables.T]] = <class 'tuple'>) Sequence[T][source]#

Ensures that the input is a sequence.

See also

ensure_iterable() for a varaint of this function which will return an interable

See also

unpack_sequence() for the inverse operation

Run checks:

  1. inp is None: returns an empty tuple

  2. inp is an instace of type: returns a tuple with inp as sole element

  3. inp implements type Sequence: return inp without modification

  4. Attempts to convert inp to a Sequence by invoking sequence_constructor

Parameters:
  • inp – Value to convert to a sequence

  • type – Type of the value(s) passed to inp

  • sequence_constructor – Callable used to convert inp to a Sequence, defaults to tuple.

Returns:

A sequence of values