How to use the yaql.language.yaqltypes.Lambda 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.parameter('index_expression', yaqltypes.Lambda())
def indexer(collection, index_expression):
    if isinstance(collection, utils.SequenceType):
        index = index_expression()
        if isinstance(index, int) and not isinstance(index, bool):
            return collection[index]
    return six.moves.filter(index_expression, collection)
github openstack / murano / murano / dsl / lhs_expression.py View on Github external
    @specs.parameter('index', yaqltypes.Lambda(with_context=True))
    def indexation(context, this, index):
        index = index(context['#root_context'])

        def getter(src):
            if utils.is_sequence(src):
                return src[index]
            else:
                raise ValueError('indexation may only be applied to lists')

        def setter(src_property, value):
            src = src_property.get()
            if utils.is_sequence(src):
                src_property.set(src[:index] + (value,) + src[index + 1:])
            elif isinstance(src, utils.MappingType):
                attribution(context, src_property, index).set(value)
github openstack / yaql / yaql / standard_library / legacy.py View on Github external
@specs.parameter('conditions', yaqltypes.Lambda(with_context=True))
@specs.no_kwargs
@specs.extension_method
def switch(value, context, *conditions):
    """:yaql:switch

    Returns the value of the first key-value pair for which condition returned
    true. If there is no such returns null.

    :signature: value.switch([args])
    :receiverArg value: value to be used evaluating conditions
    :argType value: any type
    :arg [args]: conditions to be checked for the first true
    :argType [args]: chain of mappings
    :returnType: any (appropriate value type)

    .. code::
github openstack / yaql / yaql / standard_library / boolean.py View on Github external
@specs.parameter('right', yaqltypes.Lambda())
@specs.name('#operator_or')
def or_(left, right):
    """:yaql:operator or

    Returns left operand if it evaluates to true. Otherwise evaluates right
    operand and returns it.

    :signature: left or right
    :arg left: left operand
    :argType left: any
    :arg right: right operand
    :argType right: any
    :returnType: any (left or right operand types)

    .. code::
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.parameter('value_selector', yaqltypes.Lambda())
@specs.method
def to_dict(collection, engine, key_selector, value_selector=None):
    """:yaql:dict

    Returns dict built on collection where keys are keySelector applied to
    collection elements and values are valueSelector applied to collection
    elements.

    :signature: collection.toDict(keySelector, valueSelector => null)
    :receiverArg collection: collection to build dict from
    :argType collection: iterable
    :arg keySelector: lambda function to get keys from collection elements
    :argType keySelector: lambda
    :arg valueSelector: lambda function to get values from collection elements.
        null by default, which means values to be collection items
    :argType valueSelector: lambda
github openstack / yaql / yaql / standard_library / queries.py View on Github external
    @specs.parameter('key_selector', yaqltypes.Lambda())
    @specs.parameter('value_selector', yaqltypes.Lambda())
    @specs.parameter('aggregator', yaqltypes.Lambda())
    @specs.method
    def group_by(engine, collection, key_selector, value_selector=None,
                 aggregator=None):
        """:yaql:groupBy

        Returns a collection grouped by keySelector with applied valueSelector
        as values. Returns a list of pairs where the first value is a result
        value of keySelector and the second is a list of values which have
        common keySelector return value.

        :signature: collection.groupBy(keySelector, valueSelector => null,
                                       aggregator => null)
        :receiverArg collection: input collection
        :argType collection: iterable
github openstack / yaql / yaql / standard_library / regex.py View on Github external
@specs.parameter('selector', yaqltypes.Lambda(with_context=True))
@specs.method
def search_all(context, regexp, string, selector=None):
    for res in regexp.finditer(string):
        new_context = context.create_child_context()
        if selector is None:
            yield res.group()
        else:
            _publish_match(new_context, res)
            yield selector(new_context)
github openstack / yaql / yaql / standard_library / branching.py View on Github external
@specs.parameter('args', yaqltypes.Lambda())
@specs.method
def switch_case(case, *args):
    """:yaql:switchCase

    Returns evaluated `case`-th argument. If case is less than 0 or greater
    than the amount of predicates, returns evaluated last argument.
    Returns null if no args are provided.

    :signature: case.switchCase([args])
    :recieverArg case: index of predicate to be evaluated
    :argType case: integer
    :arg [args]: input predicates
    :argType [args]: chain of any types
    :returnType: any

    .. code::
github openstack / yaql / yaql / standard_library / branching.py View on Github external
@specs.parameter('args', yaqltypes.Lambda())
def select_case(*args):
    """:yaql:selectCase

    Returns a zero-based index of the first predicate evaluated to true. If
    there is no such predicate, returns the count of arguments. All the
    predicates after the first one which was evaluated to true remain
    unevaluated.

    :signature: selectCase([args])
    :arg [args]: predicates to check for true
    :argType [args]: chain of predicates
    :returnType: integer

    .. code::

        yaql> selectCase("ab" > "abc", "ab" >= "abc", "ab" < "abc")