# Result

**Kind:** Type

**Source:** [`src/router.ts`](https://github.com/honojs/hono/blob/main/src/router.ts#L98)

Type representing the result of a route match.

The result can be in one of two formats:
1. An array of handlers with their corresponding parameter index maps, followed by a parameter stash.
2. An array of handlers with their corresponding parameter maps.

Example:

[[handler, paramIndexMap][], paramArray]
```typescript
[
  [
    [middlewareA, {}],                     // '*'
    [funcA,       {'id': 0}],              // '/user/:id/*'
    [funcB,       {'id': 0, 'action': 1}], // '/user/:id/:action'
  ],
  ['123', 'abc']
]
```

[[handler, params][]]
```typescript
[
  [
    [middlewareA, {}],                             // '*'
    [funcA,       {'id': '123'}],                  // '/user/:id/*'
    [funcB,       {'id': '123', 'action': 'abc'}], // '/user/:id/:action'
  ]
]
```

`Result` represents the output of a route match in the router. It associates matched handlers with either parameter index maps plus a shared parameter array, or with parameter maps containing resolved parameter values.

## Definition

```ts
[[T, ParamIndexMap][], ParamStash] | [[T, Params][]]
```

## Diagram

```mermaid
graph LR
  Match[Route match] --> Result[Result]
  Result --> Indexed[Handler/index-map pairs + parameter stash]
  Result --> Resolved[Handler/resolved-params pairs]
  Indexed --> Handlers[Handler entries]
  Indexed --> Stash[Parameter array]
  Resolved --> Params[Parameter maps]
```

## Usage

```ts
import type { Result } from './router'

const result: Result = [
  [
    [middlewareA, {}],
    [funcA, { id: 0 }],
    [funcB, { id: 0, action: 1 }],
  ],
  ['123', 'abc'],
]

// Resolve an indexed parameter map for a matched handler.
const [, paramIndexes] = result[0][1]
const params = Object.fromEntries(
  Object.entries(paramIndexes).map(([name, index]) => [
    name,
    result[1][index],
  ])
)

// params is { id: '123' }
```

## AI Coding Instructions

- Preserve the handler ordering in `Result`; handlers run in route-match order.
- When working with the indexed format, read parameter values from the shared parameter stash using each map's index.
- Do not treat index-map values as parameter values; they point into the parameter array.
- Support the resolved format when consuming match results, where parameter maps already contain string values.
- Keep handler and parameter-map entries paired when transforming route match results.
