Uploaded image for project: 'CloverDX'
  1. CloverDX
  2. CLO-18503

Variant foreach and in statements

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: rel-5-7-0
    • Component/s: None
    • Security Level: Users (General product issues)

      Description

      Introduce new / extend existing functions and statements:

      • foreach statement - make it work with variant. What it means is that variant can be used in place of the “iterator” variable and also one can iterate over variant variable (if that actually contains list, map or record).
        Example:
        variant any;
        any={};
        any["A"]=[1,2,3];
        any["B"]=[true, false];
        any["C"]={"name"->"John", "surname"->"Doe"};
        printErr(obj2json(any));
        foreach(variant loop : any) {
                 printErr(loop);
        }
        

        Produces:

        ERROR [main] - [1, 2, 3]
        ERROR [main] - [true, false]
        ERROR [main] - {name=John, surname=Doe}
        
      • function boolean in(..object.., ..list..|..map…|..variant..) needs to be extended to support variant data type. If variant contains list or map, the object is searched in the list/map.
        Example:
        if ("key1".in(varlist)){
            // do something
        }
        if (in("AAA",varlist[0])) {
        }
        

        Note: Function containsKey() does essentially the same, but it is an external function whereas in() is internal. Matters in compile mode where external functions have slightly more overhead.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              slamam Martin Slama
              Reporter:
              hajekt Tomas Hajek
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 10 minutes
                  10m