List::...:Typed(3pm)
π List::Objects::WithUtils::Array::Typed β bestie edition π
okay so this is a User Contributed Perl Documentation page (that's the 3pm manual section, iykyk) for List::Objects::WithUtils::Array::Typed β the array objects that actually check your types. π¦
β¨ NAME β¨
List::Objects::WithUtils::Array::Typed β type-checking array objects, fr fr. π
πΈ SYNOPSIS πΈ
use List::Objects::WithUtils 'array_of';
use Types::Standard -all;
use List::Objects::Types -all;
my $arr = array_of( Int() => 1 .. 10 );
$arr->push('foo'); # dies, failed type check
$arr->push(11 .. 15); # ok
my $arr_of_arrs = array_of( ArrayObj );
$arr_of_arrs->push([], []); # ok, coerces to ArrayObj
the way that push('foo') just dies on the spot?? π iconic behaviour honestly. and then push(11 .. 15) sails right through because those are, in fact, Ints. we love a self-aware data structure. π
and the last bit? passing [] and [] to an array-of-ArrayObj is totally fine because it coerces them into ArrayObjs for you. no cap. β¨
π DESCRIPTION π
these are type-checking array objects; elements get checked against the type you specified when the object is constructed or when new elements are added. every single time. she's thorough like that. πΈ
the first argument passed to the constructor should be a Type::Tiny type:
use Types::Standard -all;
my $arr = array_of Str() => qw/foo bar baz/;
and if the initial type-check fails, a coercion is attempted. so like, she's strict but she's not unreasonable. π«Ά
this class consumes the following roles, which contain most of the relevant documentation:
List::Objects::WithUtils::Role::ArrayList::Objects::WithUtils::Role::Array::WithJunctionsList::Objects::WithUtils::Role::Array::Typed
also see Types::Standard, List::Objects::Types β go read those too, bestie, they're literally where the good stuff lives. πβ¨
π AUTHOR π
Jon Portnoy <avenj@cobaltirc.org> with significant contributions from Toby Inkster (CPAN: TOBYINK). π shoutout to the legends, we are obsessed. π«Ά
and that's the whole page!! you read all of it, so proud of you. π
this cutie was documented for perl v5.38.2, dated 2024-03-07 β go forth and type-check your arrays, main character. π
β¨
π¦ where this page comes from
- debian trixie: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms