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.
$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.