from typing import AsyncGenerator
from typing import Optional
from typing import Callable
from typing import List


async def async_list(
        gen: AsyncGenerator,
        filter: Optional[Callable] = None) -> List:
    """Turn an async generator into a here and now list, with optional
    filter."""
    results = []
    async for x in gen:
        if filter and not filter(x):
            continue
        results.append(x)
    return results