Skip to content

Commit

Permalink
Allow --count-only and --unique to be used simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Aug 18, 2024
1 parent 6058b30 commit e960db6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 21 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for App-Rak

{{$NEXT}}
- Allow --count-only and --unique to be used simultaneously

0.3.6 2024-08-18T12:40:54+02:00
- Add support for --per-paragraph to produce haystacks
Expand Down
64 changes: 43 additions & 21 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -2497,30 +2497,52 @@ my sub move-result-options-to-rak(--> Nil) {
# Only interested in number of matches / files
elsif %result<count-only>:delete {
# Set way to stringify paths
my &stringify :=
IO::Path.^find_method(%listing<absolute>:delete
?? "absolute"
!! "relative"
);
my @files;
%rak<eager> := True;
%rak<mapper> := -> $io, @matches --> Empty {
LAST {
if $verbose {
sayer "$_.key() has $_.value() match{"es" if .value > 1}"
for @files;
if %result<unique>:delete {
%rak<sort>:delete;
%rak<omit-item-number> := True;
my int $nr-files;
my @uniques;
%rak<mapper> := -> $, @matches --> Empty {
LAST {
my int $nr-uniques = @uniques.unique.elems;
sayer $verbose
?? "$nr-uniques unique occurrenc&es($nr-uniques) in $nr-files file&s($nr-files)"
!! $nr-uniques;
}
++$nr-files;
@uniques.append: @matches.unique;
}
}
else {
# Set way to stringify paths
my &stringify :=
IO::Path.^find_method(%listing<absolute>:delete
?? "absolute"
!! "relative"
);
my @files;
%rak<mapper> := -> $io, @matches --> Empty {
LAST {
if $verbose {
sayer "$_.key() has $_.value() match{"es" if .value > 1}"
for @files;
}
my int $nr-matches = @files.map(*.value).sum;
my int $nr-files = @files.elems;
sayer $nr-files
?? "$nr-matches match&es($nr-matches) in $nr-files file&s($nr-files)"
!! "No files with matches";
}
my int $nr-matches = @files.map(*.value).sum;
my int $nr-files = @files.elems;
sayer $nr-files
?? "$nr-matches match&es($nr-matches) in $nr-files file&s($nr-files)"
!! "No files with matches";
@files.push: Pair.new:
$reading-from-stdin ?? '<STDIN>' !! stringify($io),
@matches.elems;
}
@files.push: Pair.new:
$reading-from-stdin ?? '<STDIN>' !! stringify($io),
@matches.elems;
}
}
Expand Down
32 changes: 32 additions & 0 deletions xt/01-simple.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,38 @@ eight
{BON}nine{BOFF}
OK

query-ok </./ --unique --matches-only>, ok => qq:to/OK/;
e
f
g
h
i
I
n
o
r
S
s
t
u
v
w
X
z
OK

query-ok </./ --unique --count-only>, ok => qq:to/OK/;
9
OK

query-ok </./ --unique --count-only --matches-only>, ok => qq:to/OK/;
17
OK

query-ok </./ --unique --count-only --matches-only --verbose>, ok => qq:to/OK/;
17 unique occurrences in 10 files
OK

done-testing;

# vim: expandtab shiftwidth=4

0 comments on commit e960db6

Please sign in to comment.