How to use the yaql.language.specs.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 / murano / murano / dsl / type_scheme.py View on Github external
        @specs.method
        def not_owned_ref(obj):
            if isinstance(obj, TypeScheme.ObjRef):
                return obj

            if obj is None:
                return None
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.method
@specs.parameter('collections', yaqltypes.Iterable())
def zip_longest(*collections, **kwargs):
    """:yaql:zipLongest

    Returns an iterator over collections, where the n-th iterable contains
    the n-th element from each of collections. Iterates until all the
    collections are not exhausted and fills lacking values with default value,
    which is null by default.

    :signature: collection.zipLongest([args], default => null)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg [args]: collections for zipping with input collection
    :argType [args]: chain of collections
    :arg default: default value for lacking values, can be passed only
        as keyword argument. null by default
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.method
def last(collection, default=utils.NO_VALUE):
    """:yaql:last

    Returns the last element of the collection. If the collection is empty,
    returns the default value or raises StopIteration if default is not
    specified.

    :signature: collection.last(default => NoValue)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg default: value to be returned if collection is empty. NoValue is
        default value.
    :argType default: any
    :returnType: type of collection's elements or default value type

    .. code::
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.method
def symmetric_difference(left, right):
    """:yaql:symmetricDifference

    Returns symmetric difference of left and right sets as a new set.

    :signature: left.symmetricDifference(right)
    :receiverArg left: left set
    :argType left: set
    :arg right: right set
    :argType right: set
    :returnType: set

    .. code::

        yaql> set(0, 1, 2).symmetricDifference(set(0, 1, 3))
        [2, 3]
github openstack / murano / murano / dsl / type_scheme.py View on Github external
        @specs.method
        def error(value):
            raise exceptions.ContractViolationException('error() contract')
github openstack / yaql / yaql / standard_library / strings.py View on Github external
@specs.method
def last_index_of_(string, sub, start, length):
    """:yaql:lastIndexOf

    Returns an index of last occurrence sub in string beginning from start
    ending with start+length.
    -1 is a return value if there is no any occurrence.

    :signature: string.lastIndexOf(sub, start, length)
    :receiverArg string: input string
    :argType string: string
    :arg sub: substring to find in string
    :argType sub: string
    :arg start: index to start search with, 0 by default
    :argType start: integer
    :arg length: length of string to find substring in
    :argType length: integer
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.method
def then_by(collection, selector, context):
    """:yaql:thenBy

    To be used with orderBy or orderByDescending. Uses selector to extract
    secondary sort key (ascending) from the elements of the collection and
    adds it to the iterator.

    :signature: collection.thenBy(selector)
    :receiverArg collection: collection to be ordered
    :argType collection: iterable
    :arg selector: specifies a function of one argument that is used to
        extract a comparison key from each element
    :argType selector: lambda
    :returnType: iterator

    .. code::
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.method
@specs.parameter('collection', yaqltypes.Iterable())
@specs.parameter('selector', yaqltypes.Lambda())
def accumulate(collection, selector, seed=utils.NO_VALUE):
    """:yaql:accumulate

    Applies selector of two arguments cumulatively to the items of collection
    from begin to end, so as to accumulate the collection to a list of
    intermediate values.

    :signature: collection.accumulate(selector, seed => NoValue)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg selector: function of two arguments to be applied on every next
        pair of collection
    :argType selector: lambda
    :arg seed: value to use as the first for accumulating. noValue by default
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.method
def min_(func, collection, initial=utils.NO_VALUE):
    """:yaql:min

    Returns min value in collection. Considers initial if specified.

    :signature: collection.min(initial => NoValue)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg initial: value to start with. NoValue by default
    :argType initial: collection's elements type
    :returnType: collection's elements type

    .. code::

        yaql> [3, 1, 2].min()
        1
github openstack / murano / murano / dsl / type_scheme.py View on Github external
        @specs.method
        def string(value):
            if value is dsl.NO_VALUE:
                value = default
            if value is None:
                return None
            try:
                return six.text_type(value)
            except Exception:
                raise exceptions.ContractViolationException(
                    'Value {0} violates string() contract'.format(
                        format_scalar(value)))