Help language development. Donate to The Perl Foundation

Adverb::Eject zef:lizmat last updated on 2021-11-07
[![Actions Status](](


Adverb::Eject - adverb for ejecting elements


    use Adverb::Eject;

    my @a = ^10;
    @a[1]:eject; # does *not* return the removed value
    say @a;      # 0 2 3 4 5 6 7 8 9
    say @a;      # 0 3 5 7 9

    my %h = a => 42, b => 666, c => 371;
    say %h;      # {b => 666, c => 371};
    %h<b c>:eject;
    say %h;      # {}


This module adds the `:eject` adverb to `postcircumfix []` and `postcircumfix { }`. It will remove the indicated elements from the object they're called on (usually an `Array` or a `Hash`) and always return `Nil`, whether something was removed or not.

For `Hash`es, this is similar to the `:delete` adverb, except that it will **not** return the values that have been removed.

For `Array`s, this is **also different** from the `:delete` adverb in that it will actually **remove** the indicated element from the `Array` (as opposed to just resetting the element to its pristine state).

The reason that the `:eject` adverb does not return any of the removed values is because the `:delete` already does that. And for those cases where you do not need the values, the `:eject` adverb has the potential of being more efficient because it wouldn't have to do the work of producing the values.


Elizabeth Mattijsen <[email protected]>

Source can be located at: . Comments and Pull Requests are welcome.


Copyright 2018, 2021 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.