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

Add a reverse_each function

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • PUP 4.4.0
    • Docs
    • None
    • 1
    • Language 2016-02-10
    • New Feature
    • Hide
      The function reverse_each has bee added. It works like the each function but iterates over elements in reverser order. This function in contrast to stdlib's reverse does not create a new reversed copy which makes it ideal for chaining into other Iterable functions. Also see the new puppet data types Iterable and Iterator.
      Show
      The function reverse_each has bee added. It works like the each function but iterates over elements in reverser order. This function in contrast to stdlib's reverse does not create a new reversed copy which makes it ideal for chaining into other Iterable functions. Also see the new puppet data types Iterable and Iterator.

    Description

      Add a reverse_each(iterable) function that takes one argument and an optional block. The declared parameter type must be `Iterable`.

      If the function is called without a block, it must return a new iterable that will yield each element of the given argument in reverse order.
      When a block is given, it must be called with each element of the given argument in reverse order. The argument is then returned.

      Example:

      [1,3,5,7].reverse_each |$x| { notice($x) }
      

      will result in the notices '7', '5', '3', '1'

      $c = [1,3,5,7].reverse_each.map |$x| { $x * 10 }
      

      Will result in:

      $c == [70, 50, 30, 10].
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              thomas.hallgren Thomas Hallgren
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support