from typing import Callable
from typing import Any
from typing import Iterable


def takewhile(predicate: Callable[[Any], bool], seq: Iterable) -> Iterable:
    """Lazily evaluated takewhile

    :param predicate: First failure of predicate stops the iteration. Should return bool
    :param seq: Sequence from which to take
    :returns: filtered sequence
    :rtype: Same as `seq`

    """
    it = iter(seq)
    _next = it.__next__()
    while predicate(_next):
        try:
            yield _next
            _next = it.__next__()
        except StopIteration:
            return None