-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Migrated from rt.cpan.org #133814 (status was 'open')
Requestors:
From bpjonsson@gmail.com on 2020-11-26 17:10:22
:
The subject pretty much says it all. There is ->coerce which returns the
original value if coercion fails, and ->assert_coerce which dies if
coercion fails but no middle ground which returns false if coercion fails.
It is true that it would just be sugar for Type->check(
Type->coerce($value) ) but it would be very useful sugar, because frankly
those nested calls are ugly, especially when it's inside an if test which
is commonly the case, and even more so in case you use a coercion object:
Coercion->type_constraint(Coercion->coerce($value))! I'm tempted to use try
{ Foo->assert_coerce($value) } but that is really even more ugly, although
less to type.
I can try to make a pull request if it would be welcome.