Skip to content

Commit

Permalink
Move fmt and interator methods of List to setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 22, 2009
1 parent 637767b commit f782958
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 52 deletions.
52 changes: 0 additions & 52 deletions src/classes/List.pir
Expand Up @@ -252,58 +252,6 @@ layer. It will likely change substantially when we have lazy lists.
.end
=item fmt
our Str multi List::fmt ( Str $format, $separator = ' ' )
Returns the invocant list formatted by an implicit call to C<sprintf> on each
of the elements, then joined with spaces or an explicitly given separator.
=cut
.sub 'fmt' :method :multi('ResizablePMCArray')
.param pmc format
.param string sep :optional
.param int has_sep :opt_flag
.local pmc res
.local pmc iter
.local pmc retv
.local pmc elem
.local pmc elemres
if has_sep goto have_sep
sep = ' '
have_sep:
res = new 'List'
iter = self.'iterator'()
elem_loop:
unless iter goto done
invoke:
elem = shift iter
elemres = 'sprintf'(format, elem)
push res, elemres
goto elem_loop
done:
retv = 'join'(sep, res)
.return(retv)
.end
=item iterator()
Returns an iterator for the list.
=cut
.sub 'iterator' :method
self.'!flatten'()
$P0 = iter self
.return ($P0)
.end
=item uniq(...)
=cut
Expand Down
24 changes: 24 additions & 0 deletions src/setting/List.pm
@@ -1,5 +1,29 @@
class List is also {

=begin item fmt
our Str multi List::fmt ( Str $format, $separator = ' ' )
Returns the invocant list formatted by an implicit call to C<sprintf> on each
of the elements, then joined with spaces or an explicitly given separator.
=end item
multi method fmt(Str $format, $sep = ' ') is export {
return join($sep, self.map({ sprintf($format, $^elem) }));
}

=begin item iterator()
Returns an iterator for the list.
=end item
method iterator() {
return Q:PIR {
self.'!flatten'()
%r = iter self
};
}
=begin item list
A List in list context returns itself.
Expand Down

0 comments on commit f782958

Please sign in to comment.