collection#

Core functions for collection

async idem_core_functions.exec.core.collection.distinct(hub, data: List[str]) Dict[source]#

distinct takes a list and returns a new list with any duplicate elements removed. e.g. for list [“a”, “b”, “a”, “c”, “d”, “b”], distinct returns new list [“a”, “b”, “c”, “d”]

Parameters:

data (list[str or int]) – Input list which contains duplicate values

Returns:

{"result": True|False, "comment": list, "ret": None|dict}

Examples

Calling this exec module function from the cli

idem exec core.collection.distinct data='["a", "b", "a", "c", "d", "b"]'

Using in a state:

Idem-state-name:
  exec.run:
    - path: core.collection.distinct
    - kwargs:
        data: ["a", "b", "a", "c", "d", "b"]
async idem_core_functions.exec.core.collection.flatten(hub, data: List[Any]) Dict[source]#

flatten takes a list and replaces any elements that are lists with a flattened sequence of the list. e.g. [[“a”, “b”], [], [“c”]] gets replaced to [“a”, “b”, “c”] flatten can be applied to List of numbers, strings, nested lists and mixed containers.

Parameters:

data (list[Any]) – Non flattened list

Returns:

{"result": True|False, "comment": list, "ret": None|dict}

Examples

Calling this exec module function from the cli

idem exec core.collection.flatten data='[["a", "b"], [], ["c"]]'

Using in a state:

Idem-state-name:
  exec.run:
    - path: core.collection.flatten
    - kwargs:
        data: [["a", "b"], [], ["c"]]
async idem_core_functions.exec.core.collection.element(hub, data: List[Any], index: int) Dict[source]#

Retrieves a single element from a list. element can be applied to List of numbers, strings, nested lists and mixed containers.

Parameters:
  • data (list[Any]) – List of numbers, strings, nested lists and mixed containers

  • index (int) – Zero-based index. The index must be a non-negative integer.

Returns:

{"result": True|False, "comment": list, "ret": None|dict}

Examples

Calling this exec module function from the cli

idem exec core.collection.element data='["a", "b", "c"]' index=0

Using in a state:

Idem-state-name:
  exec.run:
    - path: core.collection.element
    - kwargs:
        data: ["a", "b", "c"]
        index: 0
async idem_core_functions.exec.core.collection.length(hub, data: List) Dict[source]#

length determines the length of a given list, map, or string

Parameters:

data (list or dict or str) – List of elements or strings or a Dict of elements

Returns:

{"result": True|False, "comment": list, "ret": None|dict}

Examples

Calling this exec module function from the cli

idem exec core.collection.length data='["a", "b", "c"]'

Using in a state:

Idem-state-name:
  exec.run:
    - path: core.collection.length
    - kwargs:
        data: ["a", "b", "c"]