How to use the pydash.iteratee function in pydash

To help you get started, we’ve selected a few pydash 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 dgilland / pydash / tests / test_utilities.py View on Github external
def test_iteratee(case, arg, expected):
    getter = _.iteratee(case)
    assert _.map_(arg, getter) == expected
github dgilland / pydash / src / pydash / arrays.py View on Github external
def iterdifference(array, other, comparator=None, iteratee=None):
    """Yield different values in `array` as compared to `other` using
    `comparator` to determine if they are different.
    """
    if not array or not other:  # pragma: no cover
        return

    if comparator is None:
        comparator = pyd.is_equal

    iteratee = pyd.iteratee(iteratee)

    def is_different(item, seen):
        is_diff = True

        if item not in seen:
            for value in other:
                if comparator(iteratee(item), iteratee(value)):
                    is_diff = False
                    break

            if is_diff:
                seen.append(item)
        return is_diff

    seen = []
    not_seen = []
github dgilland / pydash / src / pydash / arrays.py View on Github external
def iterintersection(array, other, comparator=None, iteratee=None):
    """Yield intersecting values between `array` and `other` using `comparator`
    to determine if they intersect.
    """
    if not array or not other:  # pragma: no cover
        return

    if comparator is None:
        comparator = pyd.is_equal

    iteratee = pyd.iteratee(iteratee)

    # NOTE: Maintain ordering of yielded values based on `array` ordering.
    seen = []
    for item in array:
        cmp_item = iteratee(item)

        if cmp_item in seen:
            continue

        seen.append(cmp_item)
        seen_others = []

        for value in other:
            cmp_value = iteratee(value)

            if cmp_value in seen_others:
github dgilland / pydash / src / pydash / collections.py View on Github external
Returns:
        dict: Results of grouping by `iteratee`.

    Example:

        >>> results = group_by([{'a': 1, 'b': 2}, {'a': 3, 'b': 4}], 'a')
        >>> assert results == {1: [{'a': 1, 'b': 2}], 3: [{'a': 3, 'b': 4}]}
        >>> results = group_by([{'a': 1, 'b': 2}, {'a': 3, 'b': 4}], {'a': 1})
        >>> assert results == {False: [{'a': 3, 'b': 4}],\
                               True: [{'a': 1, 'b': 2}]}

    .. versionadded:: 1.0.0
    """
    ret = {}
    cbk = pyd.iteratee(iteratee)

    for value in collection:
        key = cbk(value)
        ret.setdefault(key, [])
        ret[key].append(value)

    return ret
github dgilland / pydash / src / pydash / arrays.py View on Github external
Returns:
        int: Returns the index at which `value` should be inserted into
            `array`.

    Example:

        >>> array = [{'x': 4}, {'x': 5}]
        >>> sorted_last_index_by(array, {'x': 4}, lambda o: o['x'])
        1
        >>> sorted_last_index_by(array, {'x': 4}, 'x')
        1
    """
    if iteratee:
        # Generate array of sorted keys computed using iteratee.
        iteratee = pyd.iteratee(iteratee)
        array = sorted(iteratee(item) for item in array)
        value = iteratee(value)

    return bisect_right(array, value)
github dgilland / pydash / src / pydash / arrays.py View on Github external
Args:
        array (list): List to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        list: List of duplicates.

    Example:

        >>> duplicates([0, 1, 3, 2, 3, 1])
        [3, 1]

    .. versionadded:: 3.0.0
    """
    if iteratee:
        cbk = pyd.iteratee(iteratee)
        computed = [cbk(item) for item in array]
    else:
        computed = array

    # NOTE: Using array[i] instead of item since iteratee could have modified
    # returned item values.
    lst = uniq(array[i] for i, _ in iterduplicates(computed))

    return lst
github dgilland / pydash / src / pydash / numerical.py View on Github external
Example:

        >>> max_by([1.0, 1.5, 1.8], math.floor)
        1.0
        >>> max_by([{'a': 1}, {'a': 2}, {'a': 3}], 'a')
        {'a': 3}
        >>> max_by([], default=-1)
        -1

    .. versionadded:: 4.0.0
    """
    if isinstance(collection, dict):
        collection = collection.values()

    return max(iterator_with_default(collection, default),
               key=pyd.iteratee(iteratee))
github dgilland / pydash / src / pydash / arrays.py View on Github external
int: Returns the index at which `value` should be inserted into
            `array`.

    Example:

        >>> array = [{'x': 4}, {'x': 5}]
        >>> sorted_index_by(array, {'x': 4}, lambda o: o['x'])
        0
        >>> sorted_index_by(array, {'x': 4}, 'x')
        0

    .. versionadded:: 4.0.0
    """
    if iteratee:
        # Generate array of sorted keys computed using iteratee.
        iteratee = pyd.iteratee(iteratee)
        array = sorted(iteratee(item) for item in array)
        value = iteratee(value)

    return bisect_left(array, value)

pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.

MIT
Latest version published 18 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages