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 <pproca...@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
>
>

-- 
__________________

:(){ :|:& };:

Reply via email to