Open robrwo opened 6 years ago
What's the value of returning an undef?
Useful for the coercion functions in #43:
$x = arrayref($y) // [$y]
or basically, any instance where you want the reference, or an undefined value that you can use for something else, e.g.
$x = arrayref($y) || $default;
I think if_arrayref
might be a nice naming convention. Makes it pretty clear what it's doing.
my $y = if_arrayref($x) // [];
I'm generally against returning explicit undef. I think your focus is the other side of it: returning the arrayref back so you could use it. That might be a possible change, but then the naming would be confusing:
return is_arrayref($x) || [$y];
Params::Util has "passthrough" functions that return the reference or undef instead of a boolean. This is useful.
I wouldn't recommend changing the existing API, since that could break code that expects booleans.
Maybe add simple functions like
arrayref
orhashref
etc:They could be grouped in a
:passthrough
export group.