From 314ee051c170c33d2c912b6750f916b73f9cb507 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 25 Jan 2020 15:35:02 +0000 Subject: fewer temporary variables we can `return` from an inner block, even when that block is executed somewhere else: `return` is lexical! --- lib/MaildirIndexer/Index/ByAddresses.rakumod | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/MaildirIndexer/Index/ByAddresses.rakumod') diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod index 40e98f9..c6cc412 100644 --- a/lib/MaildirIndexer/Index/ByAddresses.rakumod +++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod @@ -41,7 +41,7 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) { } method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { - MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, -> { + MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, { # ignore adding the same file twice, files in maildirs are # immutable return if %!addresses-for-file{ $email.path }:exists; @@ -56,7 +56,7 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { } method del-path(IO:D $file, Str:D $mailbox --> Nil) { - MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByAddresses'),:$mailbox, -> { + MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByAddresses'),:$mailbox, { # using assignment would fail when the path isn't present in # the hash, because it tries to assign the (undefined) # Array[Str] as a single element, instead of splatting it; @@ -93,13 +93,12 @@ submethod predict-mailbox-given-addresses(@addresses) { } method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) { - my Str $result; - MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByAddresses'), -> { + MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByAddresses'), { my %prediction = self.predict-mailbox-given-addresses($email.addresses); my @most-probable-mailboxes = %prediction.pairs.sort(*.value); - if @most-probable-mailboxes -> $_ { $result = .[*-1].key } + if @most-probable-mailboxes -> $_ { return .[*-1].key } + else { return Nil } } - return $result; } -- cgit v1.2.3