# Element removal

Extending `class Cell` from [Singly-linked\_list/Element\_definition#Raku](https://rosettacode.org/wiki/Singly-linked_list/Element_definition#Raku):

```perl
    method delete ($value --> Cell) {
        my $prev = Nil;
        my $cell = self;
        my $new-head = self;
        
        while $cell {
            my $next = $cell.next;
            if $cell.value == $value {
                $prev.next = $next if $prev;
                $cell.next = Nil;
                $new-head = $next if $cell === $new-head;
            }
            else {
                $prev = $cell;
            }
            $cell = $next;
        }
        
        return $new-head;
    }
```

Usage:

```perl
my $list = cons 10, (cons 20, (cons 10, (cons 30, Nil)));

$list = $list.delete(10);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/perl6-rosettacode/programming_tasks/s/singly-linked-list/element_removal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
