effect-io-ai

Package: effect
Module: Array

Array.intersperse

Places a separator element between every pair of elements.

When to use

Use to insert a separator between elements, for example when preparing data for display or concatenation.

Details

The return type preserves NonEmptyArray. Empty inputs produce an empty result.

Example (Interspersing a separator)

import { Array } from "effect"

console.log(Array.intersperse([1, 2, 3], 0)) // [1, 0, 2, 0, 3]

See

Signature

declare const intersperse: { <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>; <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>; <A, B>(self: Iterable<A>, middle: B): Array<A | B>; }

Source

Since v2.0.0