P21 - Insert an element at a given position into a list.

Author: Ryan Connelly

Example

> say insert-at('alfa', <a b c d>, 2);
a alfa b c d

Source code: P21-topo.pl

use v6;

sub insert-at($elem, @list is copy, $place)
{
    @list.splice($place - 1, 0, $elem);

    @list
}

say "{insert-at('alfa', <a b c d>, 2)}";