Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[S32/Containers] removed parameter to .keys etc
You could match on indexes/keys using an optional parameter on the .keys,
.values, .pairs, .enums, .kv methods. I discovered this by accident, and
went to check the source of both Rakudo and Niecza. Neither implements this
parameter. It's a very old parameter, but it seems no-one has cared about
it enough to ask for it or implement it. Besides, there are better, more
readable ways to accomplish the same thing:

    %h.values(/^prefix/);                         # instead of this...

    %h.pairs.grep({.key ~~ /^prefix/})».value;    # ...do this
    %h.kv.map({ $^value if $^key ~~ /^prefix/ }); # ...or this
    %h{%h.keys.grep(/^prefix/)};                  # ...or even this

There are plenty of alternative ways to emulate the functionality that
the parameter provided, all of them (in my opinion) more tractable.
  • Loading branch information
Carl Masak committed Mar 5, 2011
1 parent e1c674c commit 411f2a5
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions S32-setting-library/Containers.pod
Expand Up @@ -19,8 +19,8 @@ DRAFT: Synopsis 32: Setting Library - Containers.pod

Created: 19 Feb 2009 extracted from S29-functions.pod

Last Modified: 14 Jan 2011
Version: 26
Last Modified: 5 Feb 2011
Version: 27

The document is a draft.

Expand Down Expand Up @@ -732,17 +732,14 @@ returns the modified array.

=item values

multi method keys ( @array: Matcher $indextest? ) is export
multi method kv ( @array: Matcher $indextest? ) is export
multi method pairs ( @array: Matcher $indextest? ) is export
multi method enums ( @array: Matcher $indextest? ) is export
multi method values ( @array: Matcher $indextest? ) is export
multi method keys ( @array: ) is export
multi method kv ( @array: ) is export
multi method pairs ( @array: ) is export
multi method enums ( @array: ) is export
multi method values ( @array: ) is export

Iterates the elements of C<@array>, in order.

If C<$indextest> is provided, only elements whose indices match
C<$index ~~ $indextest> are iterated. (To select on values use C<grep>.)

What is returned at each element of the iteration varies with function.
C<values> returns the value of the associated element; C<kv> returns
a 2 element list in (index, value) order, C<pairs> a C<Pair(index, value)>.
Expand Down Expand Up @@ -787,19 +784,16 @@ which can be processed using junctions.

=item values

multi method keys ( %hash: Matcher $keytest? ) is export
multi method kv ( %hash: Matcher $keytest? ) is export
multi method pairs ( %hash: Matcher $keytest? ) is export
multi method enums ( %hash: Matcher $keytest? ) is export
multi method values ( %hash: Matcher $keytest? ) is export
multi method keys ( %hash: ) is export
multi method kv ( %hash: ) is export
multi method pairs ( %hash: ) is export
multi method enums ( %hash: ) is export
multi method values ( %hash: ) is export

Iterates the elements of C<%hash>. The order is implementation dependent
and arbitrary, but will be the same between successive calls to these
functions, as long as C<%hash> doesn't change.

If C<$keytest> is provided, only elements whose keys evaluate
C<$key ~~ $keytest> as true are iterated.

What is returned at each element of the iteration varies with function.
C<keys> only returns the key; C<values> the value; C<kv> returns both as
a 2 element list in (key, value) order, C<pairs> a C<Pair(key, value)>.
Expand Down

0 comments on commit 411f2a5

Please sign in to comment.