from typing import List
from typing import Any


def group_with(predicate, xs: List[Any]):
    """Takes a list and returns a list of lists where each sublist's elements are
all satisfied pairwise comparison according to the provided function.
Only adjacent elements are passed to the comparison function

    Original implementation here: https://github.com/slavaGanzin/ramda.py/blob/master/ramda/group_with.py

    Args:
        predicate ( f(a,b) => bool): A function that takes two subsequent inputs and returns True or Fale
        xs: List to group
    """
    out = []
    is_str = isinstance(xs, str)
    group = [xs[0]]

    for x in xs[1:]:
        if predicate(group[-1], x):
            group += [x]
        else:
            out.append("".join(group) if is_str else group)
            group = [x]

    out.append("".join(group) if is_str else group)

    return out