def withquerytype(query, is_function=False):
    """
    Parse query type from query component

    >>> withquerytype('{a: 5, ...}')
    ('update', '{a: 5}')
    >>> withquerytype('{a: 5}')
    ('map', '{a: 5}')
    >>> withquerytype('(.a > 5)')
    ('filter', '(.a > 5)')
    >>> withquerytype('count()', True)
    ('function', 'count()')
    >>> withquerytype('sorted(.a)', True)
    ('function', 'sorted(lambda x: (.a))')
    """
    if is_function:
        if query.startswith("unique"):
            query = query[6:]
            return "function", f"unique(lambda x: {query})"
        elif query.startswith("sorted"):
            query = query[6:]
            return "function", f"sorted(lambda x: {query})"
        elif query.startswith("yield from "):
            query = query[11:]
            return "function", f"yield_from(lambda x: {query})"
        else:
            if query.startswith("x."):
                return "function", "lambda y: map(lambda x: " + query + ", y)"
            parts = query.split("(", 1)
            if len(parts) == 1:
                return "function", "lambda y: map(lambda x: " + parts[0] + ", y)"
            if len(parts[1]) < 2:
                return "function", "(".join(parts)
            ret = "function", "(lambda x: ".join(parts)
            return ret
    elif query[-1] == ")":
        return "filter", query
    elif query[-6:] == ", ...}":
        return "update", query[:-6] + "}"
    elif query[-5:] == ",...}":
        return "update", query[:-5] + "}"
    return "map", query