[PUP-9482] add index function to return index/key in array/hash/string and other iterables Created: 2017/02/17  Updated: 2019/02/20  Resolved: 2019/02/14

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 6.3.0

Type: New Feature Priority: Normal
Reporter: 0x2A Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sub-team: Language
Team: Froyo
Release Notes: New Feature
Release Notes Summary: An `index()` function has been added to puppet that can return the index/key in an Array, Hash, String or other iterable value that is either equal to a given value or for which a given lambda returns a truthy value. Earlier this was difficult to do.
QA Risk Assessment: Needs Assessment


add an array_index function which returns the index of a specified element in an array,

see the solution in: https://ask.puppet.com/question/4763/how-to-get-an-array-index-in-manifest/


$array = ['a', 'b', 'c']
array_index($array, 'b') # returns 1

Comment by Henrik Lindberg [ 2019/02/11 ]

This question has also come up in chat and conversations. While doable, it is a bit difficult to achieve the same by using a reduce(), or by writing a function that iterates with each() and return() when a value was found. It has also been asked how to find the index to a char sequence in a string (which is even trickier).

I am taking this ticket and repurposing it for a general index() function to be added to puppet core.

Comment by Kenn Hussey [ 2019/02/12 ]

Henrik Lindberg are you still planning to get this in for Puppet 6.3 (in which case the PR needs to be merged by EOD today)?

Generated at Tue Jul 14 01:48:39 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.