<A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>
<A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>Transforms elements using a function that may return null or undefined, filtering out the null/undefined results.
When to use
Use when working with APIs or functions that return nullable values, providing a clean way to filter out null or undefined while transforming.
Example (Flat mapping nullable results)
import { Iterable } from "effect"
// Extract valid elements from nullable function results
const data = ["1", "2", "invalid", "4"]
const parsed = Iterable.flatMapNullishOr(data, (s) => {
const num = parseInt(s)
return isNaN(num) ? null : num * 2
})
console.log(Array.from(parsed)) // [2, 4, 8]
// Safe property access
const objects = [
{ nested: { value: 10 } },
{ nested: null },
{ nested: { value: 20 } },
{}
]
const values = Iterable.flatMapNullishOr(objects, (obj) => obj.nested?.value)
console.log(Array.from(values)) // [10, 20]
// Working with Map.get (returns undefined for missing keys)
const map = new Map([
["a", 1],
["b", 2],
["c", 3]
])
const keys = ["a", "x", "b", "y", "c"]
const foundValues = Iterable.flatMapNullishOr(keys, (key) => map.get(key))
console.log(Array.from(foundValues)) // [1, 2, 3]export const const flatMapNullishOr: {
<A, B>(f: (a: A) => B): (
self: Iterable<A>
) => Iterable<NonNullable<B>>
<A, B>(
self: Iterable<A>,
f: (a: A) => B
): Iterable<NonNullable<B>>
}
Transforms elements using a function that may return null or undefined, filtering out the null/undefined results.
When to use
Use when working with APIs or functions that return nullable values,
providing a clean way to filter out null or undefined while transforming.
Example (Flat mapping nullable results)
import { Iterable } from "effect"
// Extract valid elements from nullable function results
const data = ["1", "2", "invalid", "4"]
const parsed = Iterable.flatMapNullishOr(data, (s) => {
const num = parseInt(s)
return isNaN(num) ? null : num * 2
})
console.log(Array.from(parsed)) // [2, 4, 8]
// Safe property access
const objects = [
{ nested: { value: 10 } },
{ nested: null },
{ nested: { value: 20 } },
{}
]
const values = Iterable.flatMapNullishOr(objects, (obj) => obj.nested?.value)
console.log(Array.from(values)) // [10, 20]
// Working with Map.get (returns undefined for missing keys)
const map = new Map([
["a", 1],
["b", 2],
["c", 3]
])
const keys = ["a", "x", "b", "y", "c"]
const foundValues = Iterable.flatMapNullishOr(keys, (key) => map.get(key))
console.log(Array.from(foundValues)) // [1, 2, 3]
flatMapNullishOr: {
<function (type parameter) A in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>A, function (type parameter) B in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>B>(f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>A) => function (type parameter) B in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>B): (self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(f: (a: A) => B): (self: Iterable<A>) => Iterable<NonNullable<B>>B>>
<function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A, function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A>, f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A) => function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B): interface Iterable<T, TReturn = any, TNext = any>Iterable<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B>>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A, function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A>, f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>A) => function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B): interface Iterable<T, TReturn = any, TNext = any>Iterable<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(self: Iterable<A>, f: (a: A) => B): Iterable<NonNullable<B>>B>> =>
const filterMap: {
<A, B, X>(
f: (input: A, i: number) => Result<B, X>
): (self: Iterable<A>) => Iterable<B>
<A, B, X>(
self: Iterable<A>,
f: (input: A, i: number) => Result<B, X>
): Iterable<B>
}
filterMap(self: Iterable<A>self, (a: Aa) => {
const const b: Bb = f: (a: A) => Bf(a: Aa)
return const b: Bb == null ? import RR.const failVoid: Result<never, void>Provides a pre-built failed Result whose failure value is undefined.
When to use
Use when you need a failed Result value that acts only as a control signal
without failure data.
Details
This is equivalent to Result.fail(undefined) with type
Result<never, void>, but reuses a shared Failure wrapper instead of
allocating one each time.
Example (Failing without a payload)
import { Result } from "effect"
const result = Result.failVoid
console.log(Result.isFailure(result))
// Output: true
failVoid : import RR.const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(const b: NonNullable<B>b)
})
)