Remove some characters from a string by index (Raku)

.value.print if .key  !(elem) (1,2,3,8) for '0123456789'.comb.pairs

Variant of Shnipersons answer:

my $a='0123456789';
with $a {$_=.comb[(^* ∖ (1..3, 8).flat).keys.sort].join};
say $a;

In one line:

say '0123456789'.comb[(^* ∖ (1..3, 8).flat).keys.sort].join;

or called by a function:

sub remove($str, $a) {
    $str.comb[(^* ∖ $a.flat).keys.sort].join;
}

say '0123456789'.&remove: (1..3, 8);

or with augmentation of Str:

use MONKEY-TYPING;
augment class Str {
    method remove($a) {
        $.comb[(^* ∖ $a.flat).keys.sort].join;
    }
};

say '0123456789'.remove: (1..3, 8);

Tags:

Raku