Skip Menu |

This queue is for tickets about the PerlX-Maybe CPAN distribution.

Report information
The Basics
Id: 83883
Status: resolved
Priority: 0/
Queue: PerlX-Maybe

People
Owner: Nobody in particular
Requestors: dmcbride [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: (no value)



Optional export, perhaps? sub maybe_if ($$$@) { my $check = shift; if ($check) { @_ } else { (scalar @_ > 1) ? @_[2 ..$#_] : qw() } } (Rather than me producing the same thing and releasing it separately, seems like it belongs here?) Basically, this would replace: $foo ? ( key => $value ) : (), in a list with: maybe_if $foo => key => $value, in the same list. (Ok, that first fat comma could just be a regular comma.) If not, I can just create PerlX::Maybe::If, and put it there. Thanks,
On 2013-03-11T16:54:18Z, DMCBRIDE wrote: Show quoted text
> maybe_if $foo => key => $value,
I'm happy to add it, though I'll mention that it's basically the same as: grep($foo, $key => $value) ... assuming $foo is an expression which doesn't involve $_. Because: grep(0, $key => $value) returns () grep(1, $key => $value) returns ($key => $value) grep being a built-in keyword would usually offer significantly better performance.
On Mon Mar 11 13:20:34 2013, TOBYINK wrote: Show quoted text
> grep being a built-in keyword would usually offer significantly better > performance.
True, and I imagine that not using the maybe function that's already there would likely offer significantly better performance. I'm looking for "better readability" right now :) Thanks,
It would be awesome if this function could just be called "if", but alas that would blow the Perl parser's fragile little mind. So I've called it "provided" instead, as that's a rough synonym for "if". I've just uploaded PerlX::Maybe 0.003 with this function. I've also released PerlX::Maybe::XS which has a faster XS implementation. If it's installed, PerlX::Maybe will automatically use it.