Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5942

Allow a Struct type to define keys using a pattern

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Ready for Engineering
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: PUP 5.y
    • Component/s: Type System
    • Labels:
      None
    • Template:
    • Sub-team:
    • Team:
      Froyo
    • Story Points:
      2
    • Release Notes:
      New Feature
    • Release Notes Summary:
      It is now possible to use a Pattern data type to define a set of Struct type keys.

      Description

      In order to support the behavior described in PUP-4669 and for general flexibility we should allow a Struct's key to be specified by a Pattern type.

      type S1 = Struct{ regular => Integer, Pattern['prefix_.+'] => String}
      type S2 = Struct{ regular => Integer, Optional[Pattern['prefix_.+']] => String}
      type S3 = Struct{ regular => Integer, Array[Pattern['prefix_.+'], 2, 3] => String}
      

      Where a Pattern key means 0 or infinite amount of occurrences,
      an Optional around the pattern type means 0 or 1 occurrence, and an Array
      specifies min, max occurrences.

      Such that:

      $a1 = { regular => 1, prefix_a = > 10}
      $a1 =~ S1 == true
       
      $a2 = { regular => 1}
      $a2 =~ S1 == false
      $a2 =~ S2 == true
       
      $a3 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30}
      $a4 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30, prefix_d => 40}
      $a3 =~ S3 == true
      $a3 =~ S3 == true
      $a3 =~ S3 == true
       
      $a4 =~ S3 == false # a4 has too many matching keys
      $a1 =~ S3 == false  # a1 has one prefix, 2 is required
      

      • It is up to the user to construct the patterns so that they do not overlap. The struct type matches from left to right, the first pattern (if there are several) that accepts the key means that it is considered a match, and the count is associated with this struct entry. Thus, overlapping or keys with negative character set matches can cause ambiguities in the counts. This is the user's problem - it is impossible to issue a warning.
      • Type Algebra on Structs with patterns:
        • A struct is assignable to another if all after having matched all regular keys, regular keys in the RHS are matched by Pattern based keys on the LHS side, or if the set of Patterns are equal.
        • Two structs with non equal patterns are disjunct

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              henrik.lindberg Henrik Lindberg
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:

                  Zendesk Support