---------------------------------------------------------------------- This is the API documentation for the switchlang library. ---------------------------------------------------------------------- ## The switch block The context manager that gives Python an explicit switch statement. Use it in a `with` block, register cases, then read `result`. switch(value: 'Any') -> 'None' An explicit switch statement for Python, implemented as a context manager. Use it in a `with` block: register cases with `case()` and `default()`, then read the matched case's return value from `result`. See https://github.com/mikeckennedy/python-switch for full details. Copyright Michael Kennedy (https://mkennedy.codes) License: MIT ## Range helpers Helpers for mapping ranges of values to a single case. closed_range(start: 'int', stop: 'int', step: 'int' = 1) -> 'range' Create a closed range for a case: both `start` and `stop` are included. With the default step of 1, `closed_range(1, 5)` covers 1, 2, 3, 4, 5 — unlike `range(1, 5)`, the upper bound is part of the range. With a larger step the range never goes past `stop`: `closed_range(1, 6, 2)` covers 1, 3, 5, and `stop` itself is included when the step lands on it exactly, as in `closed_range(1, 7, 2)` -> 1, 3, 5, 7. ``` with switch(value) as s: s.case(closed_range(1, 5), lambda: "1-to-5") s.case(closed_range(6, 7), lambda: "6-or-7") s.default(lambda: 'default') ``` :param start: The inclusive lower bound of the range. :param stop: The inclusive upper bound of the range. :param step: The step size between elements; must be 1 or greater (defaults to 1). :return: A range object with a closed (inclusive) upper bound. :raises ValueError: If start is not less than stop, or step is less than 1.