map_collection#

composer.utils.map_collection(collection, map_fn)[source]#

Applies map_fn on each element in collection.

  • If collection is a tuple or list of elements, map_fn is applied on each element, and a tuple or list, respectively, containing mapped values is returned.

  • If collection is a dictionary, map_fn is applied on each value, and a dictionary containing the mapped values is returned.

  • If collection is None, None is returned.

  • If collection is a single element, the result of applying map_fn on it is returned.

Parameters
  • collection โ€“ The element, or a tuple of elements.

  • map_fn โ€“ A function to invoke on each element.

Returns
  • Collection โ€“ The result of applying map_fn on each element of collection.

  • The type of ``collection`` is preserved.