Skip to content

Commit

Permalink
Added "into" named parameter to Any.(classify|categorize)
Browse files Browse the repository at this point in the history
Allows you to classify into an existing hash (into => %h), or have a type of
hash created (into => Hash[Array,Int])
  • Loading branch information
lizmat committed Aug 2, 2013
1 parent 1b5924c commit 656c8cb
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ my class Any {
# derived from .list
method elems() { self.list.elems }
method end() { self.list.end }
method classify($test) { {}.classify_list( $test, self.list ) }
method categorize($test) { {}.categorize_list( $test, self.list ) }
method uniq() { self.list.uniq }
method squish() { self.list.squish }
method pick($n = 1) { self.list.pick($n) }
Expand All @@ -49,6 +47,22 @@ my class Any {
method pairs() { self.list.pairs }
method reduce(&with) { self.list.reduce(&with) }

proto method classify(|) { * }
multi method classify($test) {
{}.classify_list( $test, self.list );
}
multi method classify($test, :$into!) {
( $into // $into.new ).classify_list( $test, self.list );
}

proto method categorize(|) { * }
multi method categorize($test) {
{}.categorize_list( $test, self.list );
}
multi method categorize($test, :$into!) {
( $into // $into.new ).categorize_list( $test, self.list );
}

# derived from MapIter/list
method lol() {
MapIter.new(self.list, { .item }, Mu).list
Expand Down Expand Up @@ -807,9 +821,15 @@ multi end($a) { $a.end }

proto classify(|) { * }
multi classify( $test, *@items ) { {}.classify_list( $test, @items ) }
#multi classify( $test, *@items, :$into! ) { # problem in MMD
# ( $into // $into.new).classify_list( $test, @items );
#}

proto categorize(|) { * }
multi categorize( $test, *@items ) { {}.categorize_list( $test, @items ) }
#multi categorize( $test, *@items, :$into! ) { # problem in MMD
# ( $into // $into.new).categorize_list( $test, @items );
#}

proto uniq(|) { * }
multi uniq(*@values) { @values.uniq }
Expand Down

0 comments on commit 656c8cb

Please sign in to comment.