Skip to content

Commit

Permalink
Make .tree somewhat more to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouq committed Aug 16, 2014
1 parent 9947667 commit daf9612
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
26 changes: 17 additions & 9 deletions src/core/Any.pm
Expand Up @@ -107,16 +107,24 @@ my class Any { # declared in BOOTSTRAP

proto method tree(|) { * }
multi method tree(Any:U:) { self }
multi method tree(Any:D:) { self.lol }
multi method tree(Any:D:) {
self ~~ Positional
?? LoL.new(|MapIter.new(self.list, { .tree }, Mu).list).item
!! self
}
multi method tree(Any:D: Whatever ) { self.tree }
multi method tree(Any:D: Cool $count as Int) {
$count > 1
?? MapIter.new(self.list, { .tree($count-1).item }, Mu).list
!! $count == 1
?? self.lol
!! self
}
multi method tree(Any:D: &c) {
MapIter.new(self.list, { .&c.item }, Mu).list
self ~~ Positional && $count > 0
?? $count > 1
?? LoL.new(|MapIter.new(self.list, { .tree($count - 1) }, Mu).list).item
!! self.lol
!! self
}
multi method tree(Any:D: *@ [&first, *@rest]) {
self ~~ Positional
?? @rest ?? first MapIter.new(self.list, { .tree(|@rest) }, Mu).list
!! first self.list
!! self
}

method Array() { Array.new(self.flat) }
Expand Down
23 changes: 0 additions & 23 deletions src/core/List.pm
Expand Up @@ -69,29 +69,6 @@ my class List does Positional { # declared in BOOTSTRAP

method flattens() { $!flattens }

my &itemify = { .elems == 1 ?? $_ !! [.list] };
proto method tree(|) {*}
multi method tree(List:U:) { self }
multi method tree(List:D:) {
MapIter.new(self, &itemify, Mu).list;
}
multi method tree(List:D: Cool $count as Int) {
$count <= 0 ?? self
!! $count == 1 ?? self.tree
!! MapIter.new(
self,
{.elems == 1 ?? $_ !! [.tree($count - 1)]},
Mu
).list;
}
multi method tree(List:D: &c) {
MapIter.new(self, &c, Mu).list;
}
# uncommenting causes "Circularity detected in multi sub types"
# multi method tree(List:D: *@ [$first, *@rest] where {.elems >= 2 }) {
# MapIter.new(:list(self), :block(*.list(|@rest))).list.tree($first)
# }

method Capture() {
self.gimme(*);
my $cap := nqp::create(Capture);
Expand Down

0 comments on commit daf9612

Please sign in to comment.