<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/InlineArray/init(first:next:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11InlineArrayVsRi__rlE5first4nextAByxq_Gq__q_q_qd__YKXEtqd__YKcs5ErrorRd__lufc"
  },
  "title" : "init(first:next:)"
}
-->

# init(first:next:)

Initializes every element in this array, by calling the given closure
with each preceding element.

```
init<E>(first: consuming Element, next: (borrowing Element) throws(E) -> Element) throws(E) where E : Error
```

## Parameters

`first`

The first value to emplace into the array.

`next`

A closure that takes an immutable borrow reference to the
preceding element, and returns an owned `Element` instance to emplace
into the array.

## Discussion

This will call the closure `count - 1` times, where `count` is the static
count of the array, to initialize every element by passing the closure an
immutable borrow reference to the preceding element.

```
InlineArray<4, Int>(first: 1) { $0 * 2 }  // [1, 2, 4, 8]
```

The closure is allowed to throw an error at any point during
initialization at which point the array will stop initialization,
deinitialize every currently initialized element, and throw the given
error back out to the caller.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)