Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3911

Get unique elements from N lists

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Open
    • Priority: (None)
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Built-in functions
    • Labels:
      None

      Description

      It would be nice if I could easily get a list of unique elements from more than one list.

      Currently I need to join my lists together before finding unique elements:

      Unique entries from two lists
      bundle agent __main__
      {
        vars:
            "a" slist => { "1", "2", "3" };
            "b" slist => { "3", "4", "5" };
            "ab" slist => { @(a), @(b) };
            "u" slist => unique( @(ab) );
        reports:
            "$(u)";
      }
      
      R: 1
      R: 2
      R: 3
      R: 4
      R: 5

      Implementation Suggestions

      I think it would be reasonable to extend unique() to take N arguments.

      bundle agent __main__
      {
        vars:
            "a" slist => { "1", "2", "3" };
            "b" slist => { "3", "4", "5" };
            "u" slist => unique( @(a), @(b) );
        reports:
            "$(u)";
      }
      

      I think it would also be reasonable to extend unique() into a collecting function allowing it to take data containers.

      bundle agent __main__
      {
        vars:
            "a" slist => { "1", "2", "3" };
            "b" slist => { "3", "4", "5" };
            "u" slist => unique( mergedata( @(a), @(b) ) );
        reports:
            "$(u)";
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            a10042 Nick Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: