develooper Front page | perl.perl6.users | Postings from November 2018

Re: Need Golf!

Thread Next
From:
Paul Procacci
Date:
November 8, 2018 22:46
Subject:
Re: Need Golf!
Message ID:
CAFbbPugpOmnm4j=JB=hc9NRY2RzfSefKoSsDDouQBxgGtnKx5Q@mail.gmail.com
Had time to think about this on the drive home.
I've eliminated the for loop which was my goal.
Any "better" or "cleaner" way of doing this, I'm all ears.  ;)

die Some::Exception.new.throw
    if %!panels.elems && !%!panels.values.map({
      $end_y < .start_y || $start_x > .end_x ||
      $start_y > .end_y || $end_x < .start_x
    }).so;


On Thu, Nov 8, 2018 at 4:27 PM Paul Procacci <pprocacci@bizjournals.com>
wrote:

> I don't like this:
>
>
> for %!panels<>:k {
>      die Some::Exception.new.throw
>        unless $start_y > %!panels{$_}.end_y   || $end_y   <
> %!panels{$_}.start_y ||
>               $end_x   < %!panels{$_}.start_x || $start_x >
> %!panels{$_}.end_x;
>
> }
>
>
> In short, I have a objects stored in hash %!panels that contain the
> (x,y) coordinates of a square.
>
> The function above works; throwing an exception if any of the squares
> overlap, but I don't like using the for loop here.
>
> I'm hoping someone here can provide a similar golfed example.
>
> I've been looking at `map` and `so`, but I just can't get my brain to work.
>
>
> Thanks in Advance,
>
> ~Paul
>
>

-- 
__________________

:(){ :|:& };:

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