<A>(a: A): NonEmptyArray<A>Wraps a single value in a NonEmptyArray.
Example (Creating a single-element array)
import { Array } from "effect"
console.log(Array.of(1)) // [1]Source effect/Array.ts:33471 lines
export const const of: <A>(a: A) => NonEmptyArray<A>Wraps a single value in a NonEmptyArray.
Example (Creating a single-element array)
import { Array } from "effect"
console.log(Array.of(1)) // [1]
of = <function (type parameter) A in <A>(a: A): NonEmptyArray<A>A>(a: Aa: function (type parameter) A in <A>(a: A): NonEmptyArray<A>A): type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<function (type parameter) A in <A>(a: A): NonEmptyArray<A>A> => [a: Aa]Referenced by 31 symbols
Array.DoChannel.fromAsyncIterableArrayFileSystem.makeStream.aggregateWithinStream.chunksStream.combineStream.debounceStream.fromEffectStream.fromEffectRepeatStream.fromEffectScheduleStream.fromReadableStreamStream.fromScheduleStream.groupAdjacentByStream.interleaveWithStream.mapAccumStream.mapAccumArrayStream.mapAccumArrayEffectStream.mapAccumEffectStream.mapEffectStream.repeatElementsStream.scanStream.scanEffectStream.scheduleStream.slidingSizeStream.splitStream.succeedStream.syncStream.tickStream.transduceStream.unfoldStream.zipLatestAll