diff --git a/src/builtins/any-list.pir b/src/builtins/any-list.pir index 14711f8782f..430c391cd37 100644 --- a/src/builtins/any-list.pir +++ b/src/builtins/any-list.pir @@ -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. diff --git a/src/setting/Any-list.pm b/src/setting/Any-list.pm index 352a17c4783..942b5e0486d 100644 --- a/src/setting/Any-list.pm +++ b/src/setting/Any-list.pm @@ -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; @@ -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) }