Perl 6 module to assist with creating awesome subsets
Perl 6
Switch branches/tags
Nothing to show
Latest commit 481f1ea May 31, 2017 @zoffixznet committed on GitHub Update .travis.yml
Failed to load latest commit information.
examples first commit Apr 17, 2016
lib/Subset first commit Apr 17, 2016
logotype first commit Apr 17, 2016
t Wrote tests Apr 17, 2016
.gitignore first commit Apr 17, 2016
.travis.yml Update .travis.yml May 31, 2017
Changes first commit Apr 17, 2016
LICENSE first commit Apr 17, 2016
META6.json Use SPDX identifier in license field of META6.json Apr 27, 2017 Clearify note Apr 26, 2017

Build Status


Subset::Helper - create awesome subsets


    use Subset::Helper;

    subset Positive of Int
        where subset-is * > 0, 'Value must be above zero';

    my Positive $x = 42; # success
    my Positive $x = -2; # Fails with 'Value must be above zero';


This module solves two inconviniences with Perl 6's subsets:

1) Display of useful error messages when type check fails
2) Avoid evaluating subset's condition for `Any` values,
    which is what happens with optional parameters



    subset Positive of Int where subset-is * > 0;

    subset RoverCam of Str where subset-is
        { $_ ∈ set <MAST CHEMCAM FHAZ RHAZ> },
        'Valid cameras are MAST, CHEMCAM, FHAZ, and RHAZ';

Takes one mandatory positional argument, which is the code to execute to check the validity of value, and an optional descriptive error message to show when the value doesn't match the subset.

Note: undefined values are accepted by the subset. This exists to make it possible to cleanly define subsets for optional parameters, for which the type check is still called, even when they aren't provided in the sub/method calls.


You can't declare our scoped subsets within roles. If you're using this module, however, that error will instead point to the end of the declaration, saying expecting any of: postfix. Simply prefix your subset with my


Rakudo may evaluate whether a value matches the subset TWICE: once to check the match and once to get sensible error information.

Thus, currently the error message you provide is printed twice.

Patches to fix this are welcome.


Fork this module on GitHub:


To report bugs or request features, please use


Zoffix Znet (


You can use and distribute this module under the terms of the The Artistic License 2.0. See the LICENSE file included in this distribution for complete details.