<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
Source effect/Iterable.ts:14501 lines
export const const of: <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]
of = <function (type parameter) A in <A>(a: A): Iterable<A>A>(a: Aa: function (type parameter) A in <A>(a: A): Iterable<A>A): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(a: A): Iterable<A>A> => [a: Aa]