Ranges of enum members that dwim Inspired by this blogpost I decided to try and make it possible to have ranges of enum members that dwim, aka. that contain the actual members and not a stringified form. 

This is the result. I'm looking for comments and wether I overlook a pitfall. Also, maybe EnumMember subset can be expressed in a more performant way?

use Test;

subset EnumMember of Any where .HOW.^name eq "Perl6::Metamodel::EnumHOW";

multi sub infix:&lt;..&gt;( EnumMember $a, EnumMember $b ) 
{
    die "Can only do ranges for members of the same enum" unless $a.WHAT === $b.WHAT;
    $a.WHAT.^enum_value_list.grep({ $_ === $a fff $_ === $b })
}

enum Foo ( XA =&gt; 17, XB =&gt; 19, XC =&gt; 2, XD =&gt; 17, XE =&gt; 1, XF =&gt; 99 );
enum Goo &lt; YA YB &gt;;

is-deeply( ( XC..XE ).Array, [XC, XD, XE] ); 
dies-ok({ XA..YB });
Probably, you could do something similar by ... and succ.

enum Foo ( XA =&gt; 17, XB =&gt; 19, XC =&gt; 2, XD =&gt; 17, XE =&gt; 1, XF =&gt; 99 );
enum Goo &lt; YA YB &gt;;
XC, *.succ ... XE andthen .say


Thus your example could be rewritten

use Test;

subset EnumMember of Enumeration; 

multi sub infix:&lt;..&gt;( EnumMember:D ::T $a, T:D $b ) {
    $a, *.succ ... $b 
}

multi sub infix:&lt;..&gt;( EnumMember $a,  $b ) {
    die 'Can only do ranges for members of the same enum' 
}

enum Foo ( XA =&gt; 17, XB =&gt; 19, XC =&gt; 2, XD =&gt; 17, XE =&gt; 1, XF =&gt; 99 );
enum Goo &lt; YA YB &gt;;

is-deeply( ( XC..XE ).Array, [XC, XD, XE] ); 
dies-ok({ XA..YB }); 


But you get Seq, not Range. So I prefer redefine the sequence operator ... and make a new role instead of a subtype.

use Test;

role EnumMember {}; 

multi sub infix:&lt;...&gt;( EnumMember:D ::T $a, T:D $b ) {
    $a, *.succ ... $b 
}

multi sub infix:&lt;...&gt;( EnumMember $a,  $b ) {
    fail 'Can only do sequence for members of the same enum' 
}

multi sub infix:&lt;…&gt;( EnumMember $a,  $b ) {
  $a ... $b
}

enum Foo does EnumMember ( XA =&gt; 17, XB =&gt; 19, XC =&gt; 2, XD =&gt; 17, XE =&gt; 1, XF =&gt; 99 );
enum Goo does EnumMember &lt; YA YB &gt;;

is (XC … XE), (XC, XD, XE); 
dies-ok { XA … YB };