> For the complete documentation index, see [llms.txt](https://funkcia.lukemorales.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://funkcia.lukemorales.io/modules/runes.md).

# Runes

The Runes module provides enhanced `Map` and `Array` implementations that return `Option` types instead of `undefined` or `-1` for operations that might not find a value.

## $map

Creates a `RunicMap` instance with Option-returning methods.

```typescript
import { $map } from 'funkcia/runes';

const map = $map([
  ['key1', 'value1'],
  ['key2', 'value2'],
]);

// Returns Option<string> instead of string | undefined
const value = map.get('key1');
// Some('value1')

const missing = map.get('key3');
// None
```

## $array

Creates a `RunicArray` instance with Option-returning methods.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array([1, 2, 3]);

// Returns Option<number> instead of number | undefined
const item = arr.at(0);
// Some(1)

const missing = arr.at(10);
// None
```

### RunicArray

An `Array` subclass with Option-returning methods for safer array operations.

#### at

Returns `Some` with the item at the specified index if it exists, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array([1, 2, 3]);

const first = arr.at(0);
// Some(1)

const last = arr.at(-1);
// Some(3)

const missing = arr.at(10);
// None
```

#### find

Returns `Some` with the first element matching the predicate, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array([1, 2, 3, 4, 5]);

const even = arr.find((n) => n % 2 === 0);
// Some(2)

const large = arr.find((n) => n > 10);
// None
```

#### findIndex

Returns `Some` with the index of the first element matching the predicate, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array(['a', 'b', 'c']);

const index = arr.findIndex((item) => item === 'b');
// Some(1)

const missing = arr.findIndex((item) => item === 'z');
// None
```

#### indexOf

Returns `Some` with the index of the first occurrence of a value, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array(['a', 'b', 'c', 'b']);

const index = arr.indexOf('b');
// Some(1)

const missing = arr.indexOf('z');
// None
```

#### lastIndexOf

Returns `Some` with the index of the last occurrence of a value, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array(['a', 'b', 'c', 'b']);

const index = arr.lastIndexOf('b');
// Some(3)
```

#### pop

Removes and returns `Some` with the last element if it exists, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array([1, 2, 3]);

const last = arr.pop();
// Some(3)
// arr is now [1, 2]

const empty = $array<number>([]);
const nothing = empty.pop();
// None
```

#### shift

Removes and returns `Some` with the first element if it exists, otherwise `None`.

```typescript
import { $array } from 'funkcia/runes';

const arr = $array([1, 2, 3]);

const first = arr.shift();
// Some(1)
// arr is now [2, 3]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://funkcia.lukemorales.io/modules/runes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
