(input: unknown): input is Iterable<unknown>Checks whether a value is iterable.
When to use
Use when you need a Predicate guard before iterating an unknown value.
Details
Accepts strings as iterable and uses hasProperty for Symbol.iterator.
Example (Guarding iterables)
import { Predicate } from "effect"
const data: unknown = [1, 2, 3]
console.log(Predicate.isIterable(data))Source effect/Predicate.ts:12883 lines
export function function isIterable(
input: unknown
): input is Iterable<unknown>
Checks whether a value is iterable.
When to use
Use when you need a Predicate guard before iterating an unknown value.
Details
Accepts strings as iterable and uses hasProperty for Symbol.iterator.
Example (Guarding iterables)
import { Predicate } from "effect"
const data: unknown = [1, 2, 3]
console.log(Predicate.isIterable(data))
isIterable(input: unknowninput: unknown): input: unknowninput is interface Iterable<T, TReturn = any, TNext = any>Iterable<unknown> {
return const hasProperty: <typeof Symbol.iterator>(self: unknown, property: typeof Symbol.iterator) => self is { [K in typeof Symbol.iterator]: unknown; } (+1 overload)hasProperty(input: unknowninput, var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator) || function isString(
input: unknown
): input is string
Checks whether a value is a string.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
string.
Details
Uses typeof input === "string".
Example (Guarding strings)
import { Predicate } from "effect"
const data: unknown = "hi"
if (Predicate.isString(data)) {
console.log(data.toUpperCase())
}
isString(input: unknowninput)
}