Closed alranel closed 6 years ago
I don't think this is something I'd want to add. This seems like it could easily lead to a lot of bugs for people expecting the existing behavior.
I could imagine maybe having optional_to
and optional_cc
exports, but it seems like overkill for something you can do pretty easily on the caller's side:
build_email(
( @to ? to(@to) : () ),
( @cc ? cc(@cc) : () ),
...
)
I forgot to say thanks for the suggestion and the PR.
This seems like it could easily lead to a lot of bugs for people expecting the existing behavior.
Can you elaborate on "lots of bugs"? What's a scenario do you think this PR would disrupt? The only affected scenario would be when someone is supplying no arguments and relying on Courriel to croak, which would be a very unusual pattern for checking an array for emptiness.
By "a lot of bugs" I mean that changing something from throwing an exception to not throwing one can easily break code. I don't think relying on a library to continue to throw an exception is unusual.
Currently,
to()
andcc()
require at least one argument, otherwise they'd fail like this:However, since the
build_email()
syntax is not very OOP and does not make conditional building easy, a quick way for adding recipients only when we have them is needed. In case we supply an empty list, I'd just expectto()
andcc()
to behave as no-ops.This pull request leverages the
optional
argument provided by Params::ValidationCompiler.