# Non empty lists using Zippers

{% tabs %}
{% tab title="Problem" %}

```
type alias Book =
    List Page

currentPage : Book -> Page
currentPage book =
    case book of
        page :: _ ->
            page
        [] ->
            Debug.todo "this is a dead end."
   
```

{% endtab %}

{% tab title="Solution" %}

```
type alias Book =
    { previous : List Page
    , current : Page
    , next : List Page
    }

currentPage : Book -> Page
currentPage book =
    book.current
```

{% endtab %}
{% endtabs %}

## Question

How can I  ensure that a list always contains at least one element.

## Answer

Such a list is called a **Zipper List**:

```
type alias ZipperList a =
    { previous : List a
    , current : a
    , next : List a
    }
```

{% hint style="info" %}
**Package:** Use [miyamoen/select-list](https://package.elm-lang.org/packages/miyamoen/select-list/latest) for a complete implementation of a Zipper List.
{% endhint %}

## Further reading

* 📦**Package:** [miyamoen/select-list](https://package.elm-lang.org/packages/miyamoen/select-list/latest)
* 📦**Package:** [wernerdegroot/listzipper](https://package.elm-lang.org/packages/wernerdegroot/listzipper/latest/)


---

# 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://orasund.gitbook.io/elm-cookbook/recipes-1/making-impossible-states-impossible/non-empty-lists-using-zippers.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.
