maplist

Table of Contents

Prototype: maplist(pattern, list)

Return type: slist

Description: Return a list with each element in list modified by a pattern.

This function can accept many types of data parameters.

This function can delay the evaluation of its first parameter, which can therefore be a function call.

The $(this) variable expands to the currently processed entry from list. This is essentially like the map() function in Perl, and applies to lists.

Arguments:

  • pattern: string - Pattern based on $(this) as original text - in the range: .*
  • list: string - CFEngine variable identifier or inline JSON - in the range: .*

Example:

body common control
{
      bundlesequence => { "example" };
}

bundle common g
{
  vars:

      "otherlist" slist => { "x", "y", "z" };
}


bundle agent example

{
  vars:

      "oldlist" slist => { "a", "b", "c" };

      "newlist1" slist => maplist("Element ($(this))","@(g.otherlist)");
      "newlist2" slist => maplist("Element ($(this))",@(oldlist));

  reports:
      "Transform: $(newlist1)";
      "Transform: $(newlist2)";
}

Output:

R: Transform: Element (x)
R: Transform: Element (y)
R: Transform: Element (z)
R: Transform: Element (a)
R: Transform: Element (b)
R: Transform: Element (c)

History: Was introduced in 3.3.0, Nova 2.2.0 (2011). The collecting function behavior was added in 3.9. The delayed evaluation behavior was introduced in 3.10.

See also: maplist(), maparray(), about collecting functions, and data documentation.