in reply to Re: Coerce or transform with Types::Param
in thread Coerce or transform with Types::Param

I too hoped you'd reply.

Your code is far less verbose than mine too.

There are a couple of concepts that are new to me there, I've not come across of before and I haven't see a Type modified with where in that way either. I only considered where in the constructor so that is really useful.

...
my $MaybeCaption = Maybe ->of( $LongCaption ) ->plus_coercions( $EmptyStr => q{ undef } );
Really appreciate the help.
Dermot

Replies are listed 'Best First'.
Re^3: Coerce or transform with Types::Param
by tobyink (Canon) on Mar 21, 2021 at 20:33 UTC

    of is a shorthand for parameterizing a type. If you do something like this, it will fail:

    if ( ArrayRef[Int]->check( \@numbers ) ) { ...; }

    And you need to add some parentheses which look pretty ugly:

    if ( ( ArrayRef[Int] )->check( \@numbers ) ) { ...; }

    The of method look a little nicer:

    if ( ArrayRef->of( Int )->check( \@numbers ) ) { ...; }

    And where is a shorthand for creating a child type with an additional restriction.