How to use the yaql.language.specs.extension_method function in yaql

To help you get started, we’ve selected a few yaql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / yaql / yaql / standard_library / legacy.py View on Github external
@specs.extension_method
def dict_(delegate, *tuples):
    """:yaql:dict

    Returns dict built from tuples.

    :signature: dict([args])
    :arg [args]: chain of tuples to be interpreted as (key, value) for dict
    :argType [args]: chain of tuples
    :returnType: dictionary

    .. code::

        yaql> dict(a => 1, b => 2)
        {"a": 1, "b": 2}
        yaql> dict(tuple(a, 1), tuple(b, 2))
        {"a": 1, "b": 2}
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.extension_method
def count_(collection):
    """:yaql:len

    Returns the size of the collection.

    :signature: collection.len()
    :receiverArg collection: input collection
    :argType collection: iterable
    :returnType: integer

    .. code::

        yaql> [1, 2].len()
        2
    """
    count = 0
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.extension_method
@specs.name('len')
def sequence_len(sequence):
    """:yaql:len

    Returns length of the list.

    :signature: sequence.len()
    :receiverArg sequence: input sequence
    :argType dict: sequence
    :returnType: integer

    .. code::

        yaql> [0, 1, 2].len()
        3
    """
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.extension_method
def distinct(engine, collection, key_selector=None):
    """:yaql:distinct

    Returns only unique members of the collection. If keySelector is
    specified, it is used to determine uniqueness.

    :signature: collection.distinct(keySelector => null)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg keySelector: specifies a function of one argument that is used
        to extract a comparison key from each collection element. The default
        value is null, which means elements are compared directly
    :argType keySelector: lambda
    :returnType: iterable

    .. code::
github openstack / murano / murano / engine / system / yaql_functions.py View on Github external
@specs.extension_method
def pselect(collection, composer):
    return helpers.parallel_select(collection, composer)
github openstack / murano / murano / dsl / yaql_functions.py View on Github external
@specs.extension_method
def find(obj, murano_class_ref):
    return obj.find_owner(murano_class_ref, optional=True)
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.extension_method
def concat(*collections):
    """:yaql:concat

    Returns an iterator that consequently iterates over elements of the first
    collection, then proceeds to the next collection and so on.

    :signature: collection.concat([args])
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg [args]: iterables to be concatenated with input collection
    :argType [args]: chain of iterable
    :returnType: iterable

    .. code::

        yaql> [1].concat([2, 3], [4, 5])
github openstack / murano / murano / engine / system / yaql_functions.py View on Github external
@specs.extension_method
def bind(obj, mappings):
    if isinstance(obj, str) and obj.startswith('$'):
        value = _convert_macro_parameter(obj[1:], mappings)
        if value is not None:
            return value
    elif utils.is_sequence(obj):
        return [bind(t, mappings) for t in obj]
    elif isinstance(obj, collections.Mapping):
        result = {}
        for key, value in obj.items():
            result[bind(key, mappings)] = bind(value, mappings)
        return result
    elif isinstance(obj, str) and obj.startswith('$'):
        value = _convert_macro_parameter(obj[1:], mappings)
        if value is not None:
            return value
github openstack / murano / murano / dsl / yaql_functions.py View on Github external
@specs.extension_method
def require(value):
    if value is None:
        raise ValueError('Required value is missing')
    return value
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.extension_method
@specs.name('len')
def dict_len(d):
    """:yaql:len

    Returns size of the dictionary.

    :signature: dict.len()
    :receiverArg dict: input dictionary
    :argType dict: mapping
    :returnType: integer

    .. code::

        yaql> {"a" => 1, "b" => 2}.len()
        2
    """