Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create Setty.new-fp so that the .Set and .KeySet coercers can use that
  • Loading branch information
lizmat committed Sep 7, 2013
1 parent 06622f7 commit 22622a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/core/Any.pm
Expand Up @@ -741,22 +741,8 @@ my class Any { # declared in BOOTSTRAP
}
method FLATTENABLE_HASH() { nqp::hash() }

method Set() {
my @keys;
for self.list() {
when Pair { @keys.push(.key) if .value }
default { @keys.push($_) }
}
Set.new(@keys);
}
method KeySet() {
my @keys;
for self.list() {
when Pair { @keys.push(.key) if .value; }
default { @keys.push($_) }
}
KeySet.new(@keys);
}
method Set() { Set.new-fp(self.list) }
method KeySet() { KeySet.new-fp(self.list) }
method Bag() { Bag.new-fp(self.list) }
method KeyBag() { KeyBag.new-fp(self.list) }
}
Expand Down
12 changes: 12 additions & 0 deletions src/core/Setty.pm
Expand Up @@ -52,6 +52,18 @@ my role Setty does Associative {
%e{$_.WHICH} = $_ for @args;
self.bless(:elems(%e));
}
method new-fp(*@pairs --> Setty) {
my %e;
for @pairs {
when Pair {
%e{.key.WHICH} //= $_.key if .value;
}
default {
%e{.WHICH} //= $_;
}
}
self.bless(:elems(%e));
}

method ACCEPTS($other) {
self.defined
Expand Down

0 comments on commit 22622a9

Please sign in to comment.