Skip to content

Commit

Permalink
moved kv to setting
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
dakkar authored and moritz committed Aug 9, 2009
1 parent 212b145 commit 7d06fad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/builtins/any-list.pir
Expand Up @@ -94,46 +94,6 @@ Return a List with the keys of the invocant.
signature."!add_implicit_self"($P0)
.end


=item kv

=cut

.namespace []
.sub 'kv' :multi() :subid('_kv')
.param pmc values :slurpy
values.'!flatten'()
.tailcall values.'kv'()
.end
.sub '' :init :load
.local pmc block, signature
.const 'Sub' $P0 = "_kv"
block = $P0
signature = new ["Signature"]
setprop block, "$!signature", signature
signature.'!add_param'('@values', 1 :named('slurpy'))
'!TOPERL6MULTISUB'(block)
.end

.namespace ['Any']
.sub 'kv' :method
.local pmc result, it
result = new ['List']
it = self.'iterator'()
.local int i
i = 0
loop:
unless it goto done
$P0 = shift it
push result, i
push result, $P0
inc i
goto loop
done:
.return (result)
.end


=item pick($num, :$repl)

=cut
Expand Down
15 changes: 15 additions & 0 deletions src/setting/Any-list.pm
Expand Up @@ -85,6 +85,17 @@ class Any is also {
}
}
our List multi method kv() {
my $i=0;
gather {
for @.list -> $value {
take 0+$i;
take $value;
++$i
}
}
}
multi method reduce(Code $expression is rw) {
my Int $arity = $expression.count;
fail('Cannot reduce() using a unary or nullary function.')
Expand Down Expand Up @@ -133,6 +144,10 @@ our Str multi join(Str $separator = '', *@values) {
@values.join($separator)
}

our List multi sub kv(*@values) is export {
@values.kv();
}

our List multi map(Code $expr, *@values) {
@values.map($expr)
}
Expand Down

0 comments on commit 7d06fad

Please sign in to comment.