from typing import Mapping
import functools


def replace_multiple_substrings(s_in: str, subs: Mapping[str, str]) -> str:
    """
    Replace multiple substrings within the given input string.

    The order in which the replacements occur cannot be guaranteed.

    Parameters
    ----------
    s_in: str
        Input string to make the substitutions in.
    sub: mapping of str to str
        Keys in this dict are substrings to replace, with each values
        being the string the key should be replaced with.

    Examples
    --------
    >>> from glo.helpers import replace_multiple_substrings
    >>> replace_multiple_substrings("a test", {"a": "hey", "test": "there"})
    'hey there'
    >>> replace_multiple_substrings("12546", {"5": "3", "6": "321"})
    '1234321'
    """

    return functools.reduce(
        lambda result, next_sub: result.replace(*next_sub), subs.items(), s_in
    )