develooper Front page | perl.perl5.porters | Postings from July 2021

Elevator pitch - "assuming"

Thread Next
From:
Veesh Goldman
Date:
July 27, 2021 23:35
Subject:
Elevator pitch - "assuming"
Message ID:
CAO-W_8A6XGcWGTheRo741UUB9Ld0nvtM986Ez+CX=o7ohkkGdQ@mail.gmail.com
I frequently find myself writing lines of code like the following

$row->{nested}{key} = mutate_it($row->{nested}{key}) if $row->{nested}{key}

And I find it annoying that I have to keep repeating the name of the
variable. The line processes a value if it's truthy, and leaving it falsy
otherwise.

it would be nice if we had a conditional statement that would also
topicalize, so that it could be cut down to
$_ = mutate_it($_) assuming $row->{nested}{key}

Open questions that come to mind is what conditions other than truthiness
would look like. Something like assuming $row->{nested}{key} : exists $_
perhaps?

In terms of what the argument to assuming would be, I guess any lvalue
would make sense.

Existing options:
There is a &&= operator, but it would still require duplication of lengthy
unravelings.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About