How to use yaql - 10 common examples

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 / math.py View on Github external
@specs.parameter('right', yaqltypes.Number())
@specs.name('#operator_/')
def division(left, right):
    if isinstance(left, six.integer_types) and isinstance(
            right, six.integer_types):
        return left // right
    return left / right
github openstack / yaql / yaql / functions / arithmetic.py View on Github external
@parameter('b', custom_validator=_is_a_number)
def divide(a, b):
    if isinstance(a, six.integer_types) and isinstance(b, six.integer_types):
        return a // b
    return a / b
github openstack / yaql / yaql / standard_library / regex.py View on Github external
@specs.parameter('regexp', REGEX_TYPE)
@specs.parameter('string', yaqltypes.String())
@specs.parameter('max_split', int)
@specs.method
def split(regexp, string, max_split=0):
    return regexp.split(string, max_split)
github openstack / murano / murano / dsl / helpers.py View on Github external
def patch_dict(dct, path, value):
    parts = path.split('.')
    for i in range(len(parts) - 1):
        if not isinstance(dct, dict):
            dct = None
            break
        dct = dct.get(parts[i])
    if isinstance(dct, dict):
        if value is yaqlutils.NO_VALUE:
            dct.pop(parts[-1])
        else:
            dct[parts[-1]] = value
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.parameter('collection', yaqltypes.Iterable())
@specs.parameter('selector', yaqltypes.Lambda())
@specs.method
def select_many(collection, selector):
    """:yaql:selectMany

    Applies a selector to each element of the collection and returns an
    iterator over results. If the selector returns an iterable object,
    iterates over its elements instead of itself.

    :signature: collection.selectMany(selector)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg selector: function to be applied to every collection element
    :argType selector: lambda
    :returnType: iterator
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.parameter('count', int)
@specs.parameter('values', yaqltypes.Iterable())
def replace_many(collection, position, values, count=1):
    """:yaql:replaceMany

    Returns collection where [position, position+count) elements are replaced
    with values items.

    :signature: collection.replaceMany(position, values, count => 1)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg position: index to start replace
    :argType position: integer
    :arg values: items to replace
    :argType values: iterable
    :arg count: how many elements to replace, 1 by default
    :argType count: integer
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.parameter('d', utils.MappingType, alias='dict')
@specs.parameter('keys', yaqltypes.Iterable())
def delete_keys_seq(d, keys):
    """:yaql:deleteAll

    Returns dict with keys removed. Keys are provided as an iterable
    collection.

    :signature: dict.deleteAll(keys)
    :receiverArg dict: input dictionary
    :argType dict: mapping
    :arg keys: keys to be removed from dictionary
    :argType keys: iterable
    :returnType: mapping

    .. code::
github openstack / murano / murano / dsl / yaql_functions.py View on Github external
@specs.parameter('object_', dsl.MuranoObjectParameter(decorate=False))
@specs.parameter('func', yaqltypes.Lambda())
def super_(context, object_, func=None):
    cast_type = helpers.get_type(context)
    if func is None:
        return [object_.cast(type) for type in cast_type.parents]
    return map(func, super_(context, object_))
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.parameter('value', nullable=True)
@specs.parameter('position', int)
@specs.name('insert')
def iter_insert(collection, position, value):
    """:yaql:insert

    Returns collection with inserted value at the given position.

    :signature: collection.insert(position, value)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg position: index for insertion. value is inserted in the end if
        position greater than collection size
    :argType position: integer
    :arg value: value to be inserted
    :argType value: any
    :returnType: iterable
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.parameter('collection', yaqltypes.Iterable())
@specs.method
def single(collection):
    """:yaql:single

    Checks that collection has only one element and returns it. If the
    collection is empty or has more than one element, raises StopIteration.

    :signature: collection.single()
    :receiverArg collection: input collection
    :argType collection: iterable
    :returnType: type of collection's elements

    .. code::

        yaql> ["abc"].single()
        "abc"