def snake_to_camel(s):
    """Converts snake_case to camelCase.

    Consecutive underscores in the input will be treated as a single
    underscore. Trailing underscores will be discarded.

    :param str s: The snake case string to transform.

    :return: a camel case string
    :rtype: str
    """
    def characters():
        was_underscore = False
        for c in s:
            if c == '_':
                was_underscore = True
            else:
                yield c.upper() if was_underscore else c
                was_underscore = False
    return ''.join(characters())