You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
one can argue that the current caching behaviour of :nth in Str.match is faulty. This faulty behaviour is however tested for in roast.
So what is the new behaviour in short:
- :nth doesn’t cache, but is fully lazy
- :nth(N) gives the Nth match, or Nil if there isn’t an Nth match
- :nth(*|Inf) gives the last match, or Nil if there aren’t any matches
- :nth(anything that can do .iterator) gives a list of matches on the proviso that the numeric values of the iterator are monotonically increasing: any deviance from this is an exception (as is starting from 0, which is not monotonically increasing from the 1st match).
- :st, :nd, :rd, :th continue to be synonyms for :nth
- :x keeps its caching behaviour, and can be used in combination with :nth.
Examples:
$ 6 'say "abc".match(/./,:nth(2,3,4))'
(「b」 「c」)
$ 6 'say "abc".match(/./,:nth(2,4,3))’
(「b」) # seeing index #4 stops iteration, as there is no 4th match
$ 6 'say "abc".match(/./,:nth(3,2,1))'
Attempt to fetch match #2 after #3
Migrated from rt.perl.org#129945 (status was 'new')
Searchable as RT129945$
The text was updated successfully, but these errors were encountered: