Skip to content

Commit

Permalink
Moved join method from builtins to setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
cspencer committed Apr 18, 2009
1 parent 6739243 commit 669fb45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
24 changes: 0 additions & 24 deletions src/builtins/any-list.pir
Expand Up @@ -55,30 +55,6 @@ the size of that file down and to emphasize their generic,
.return ($I0)
.end

=item join

=cut

.namespace []
.sub 'join' :multi('String')
.param string sep
.param pmc values :slurpy
.tailcall values.'join'(sep)
.end

.namespace ['Any']
.sub 'join' :method :multi(_)
.param string sep :optional
.param int has_sep :opt_flag
if has_sep goto have_sep
sep = ''
have_sep:
$P0 = self.'list'()
$P0.'!flatten'()
$S0 = join sep, $P0
.return ($S0)
.end

=item keys()

Return a List with the keys of the invocant.
Expand Down
9 changes: 9 additions & 0 deletions src/setting/Any-list.pm
Expand Up @@ -11,6 +11,10 @@ class Any is also {
}
}

our Str multi method join(Str $separator = '') {
@.list.reduce({ $^a ~ $separator ~ $^b })
}

our List multi method map(*&expr) {
return gather {
my $arity = &expr.arity || 1;
Expand Down Expand Up @@ -97,6 +101,11 @@ our List multi grep(Code $test, *@values) {
@values.grep($test)
}

our Str multi join(Str $separator = '', *@values) {
die("Not enough arguments for join") if ! @values;
@values.join($separator)
}

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

0 comments on commit 669fb45

Please sign in to comment.