Hyperlinkv0.8.0-beta.28

Iterable

Iterable.ofconsteffect/Iterable.ts:1450
<A>(a: A): Iterable<A>

Creates an iterable containing a single element.

When to use

Use to wrap a single value in an iterable context so it can be combined with other iterable operations.

Example (Wrapping a single value)

import { Iterable } from "effect"

const single = Iterable.of(42)
console.log(Array.from(single)) // [42]

// Useful for creating homogeneous sequences
const sequences = [
  Iterable.of("hello"),
  Iterable.range(1, 3),
  Iterable.empty<string>()
]

// Can be used with flatMap for conditional inclusion
const numbers = [1, 2, 3, 4, 5]
const evensOnly = Iterable.flatMap(
  numbers,
  (n) => n % 2 === 0 ? Iterable.of(n) : Iterable.empty()
)
console.log(Array.from(evensOnly)) // [2, 4]
constructors
export const of = <A>(a: A): Iterable<A> => [a]