# KHeapFactory

> **KHeapFactory** = <`A`>(`k`, `order`, `items?`) => [`KHeap`](/reference/knotkit/heap/interfaces/kheap/)<`A`>

Defined in: [packages/heap/src/k-heap.ts:133](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/k-heap.ts#L133)

Create a [KHeap](/reference/knotkit/heap/interfaces/kheap/) of arity `k` from an order and an optional iterable of items.

Separate from `BinaryHeapFactory` because the arity is a construction parameter rather than part of the kind: `KHeapKind` records the direction, not `k`.

## Type Parameters

### A

`A`

## Parameters

### k

`number`

### order

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`A`>

### items?

`Iterable`<`A`>

## Returns

[`KHeap`](/reference/knotkit/heap/interfaces/kheap/)<`A`>

## Throws

With code `INVALID_ARITY` when `k` is not an integer of at least 2.
