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

Add ability to return multiple named values from a function.

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Language
    • Labels:
      None
    • Template:
    • Sub-team:
    • Team:
      Server
    • QA Risk Assessment:
      Needs Assessment

      Description

      This is inspired from Golang where it is possible to return several values from a function and also to declare variables as part of the declaration of the return value.

      Consider the following function:

      function multiReturn() >> Struct[a=>String,b=>Integer] {
        $a = 'hello'
        $b = 3
        return { a => $a, b => $b }
      }
      

      this could instead be written as:

      function multiReturn() >> (String $a, Integer $b) {
        $a = 'hello'
        $b = 3
      }
      

      The result would in both cases be:

      { a => 'hello', b => 3 }
      

      This new syntax also aligns well with the already existing ability to assing multiple returns to named variables of an Array, e.g.

      [ $a, $b ] = multiReturn()
      

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                Unassigned
                Reporter:
                thomas.hallgren Thomas Hallgren
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: