An easy way to filter arrays
Currently, if we want to filter an array we need to use %var(#?pattern)
, then loop over the indices returned and construct a new array. Another suggestion already exists to get rid of that loop by allowing %var(1,5,7)
to return an array with just those indices and I agree that'd be a nice improvement. There it is then suggested that we could then use %var(%var(#?pattern))
to filter an array. However, I think for that special case we can do even better.
We currently already have %var(#>)
/%var(>)
and %var(#<)
/%var(<)
, where the version with #
returns the index and the other the value, we could have a similar syntax here by making %var(?pattern)
return the filtered array directly. And of course that would imply %var(?~Rregex)
should filter by regex.
Note that allowing multiple indices as in the suggestion linked above will still be useful for cases where parallel arrays use matching indices for related values (since you'd want to filter all of those using the same indices) as well as cases where the indices are computed in some other way.