Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document infix:<but> with object as RHS
  • Loading branch information
zoffixznet committed Nov 27, 2016
1 parent 2b2a9be commit 08b6467
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doc/Language/operators.pod6
Expand Up @@ -1223,14 +1223,22 @@ to act like a role, for example enum values.
=head2 infix C«but»
=begin code :skip-test
sub infix:<but>(Mu $obj, Mu $role) is assoc<non>
sub infix:<but>(Mu $obj, Mu $role) is assoc<non>
sub infix:<but>(Mu $obj, Mu:D $obj) is assoc<non>
=end code
Creates a copy of C<$obj> with C<$role> mixed in. Since C<$obj> is not
modified, C<but> can be used to created immutable values with mixins.
C<$role> doesn't need to a be a role, it can be something that knows how
to act like a role, for example enum values.
Instead of a role, you can provide an instantiated object. In this case,
the operator will create a role for you automatically. The role will contain
a single method named the same as C<$obj.^name> and that returns C<$obj>:
say 42 but 'forty two'; # 'forty two'
my $s = 12 but class { method ^name ($) { 'warbles' } }.new;
say $s.warbles; # warbles.new
say $s + 42; # 54
=head2 infix C«cmp»
Expand Down

0 comments on commit 08b6467

Please sign in to comment.