Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom operator to suppress sink context

Tags:

raku

multi sub infix:<*>( Numeric $i, Block $b ) { &$b($_) for ^($i.Int); }
3 * { .say };

Yields

Useless use of "*" in expression "3 * { .say }" in sink context

How do I get rid of that and make my operator work? I know I could assign it to $ or something else, but I don't want that.

like image 897
Holli Avatar asked Mar 23 '20 19:03

Holli


1 Answers

Add this line to the start of your code:

proto sub infix:<*> ( | --> Nil ) {*}

See my answer to Impossible to put a map in sink context for a little on the --> Nil part of this (along with a boatload of irrelevant stuff too) including Larry's 2012 comment:

--> Nil seems like pretty good documentation of a procedure done only for its side-effects

like image 131
raiph Avatar answered Jan 01 '23 20:01

raiph