<A, B, X, E, R>(
filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
options?: { readonly concurrency?: Concurrency | undefined }
): (elements: Iterable<A>) => Effect<Array<B>, E, R>
<A, B, X, E, R>(
elements: Iterable<A>,
filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
options?: { readonly concurrency?: Concurrency | undefined }
): Effect<Array<B>, E, R>Filters and maps elements of an iterable effectfully with a FilterEffect.
When to use
Use when you need to filter each iterable element effectfully and transform accepted elements into successful output values.
Details
Result.succeed values are collected in the returned array, and
Result.fail values are skipped.
Gotchas
With concurrent execution, successful values are collected in completion order, not input order.
export const const filterMapEffect: {
<A, B, X, E, R>(
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>,
options?: {
readonly concurrency?:
| Concurrency
| undefined
}
): (
elements: Iterable<A>
) => Effect<Array<B>, E, R>
<A, B, X, E, R>(
elements: Iterable<A>,
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>,
options?: {
readonly concurrency?:
| Concurrency
| undefined
}
): Effect<Array<B>, E, R>
}
Filters and maps elements of an iterable effectfully with a FilterEffect.
When to use
Use when you need to filter each iterable element effectfully and transform
accepted elements into successful output values.
Details
Result.succeed values are collected in the returned array, and
Result.fail values are skipped.
Gotchas
With concurrent execution, successful values are collected in completion
order, not input order.
filterMapEffect: {
<function (type parameter) A in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
A, function (type parameter) B in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
B, function (type parameter) X in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
X, function (type parameter) E in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
R>(
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>
filter: import FilterFilter.interface FilterEffect<in Input, out Pass, out Fail, out E = never, out R = never>Represents an effectful filter function that can produce Effects.
Details
Similar to a regular Filter, but the filtering operation itself can be
effectful, allowing for asynchronous operations, error handling, and
dependency injection.
Example (Defining an effectful user filter)
import { Effect, Filter, Result } from "effect"
// An effectful filter that validates user data
type User = { id: string; isActive: boolean }
type ValidationError = { message: string }
const validateUser: Filter.FilterEffect<
string,
User,
User,
ValidationError,
never
> = (id) =>
Effect.gen(function*() {
const user: User = { id, isActive: id.length > 0 }
return user.isActive ? Result.succeed(user) : Result.fail(user)
})
FilterEffect<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
A>, function (type parameter) B in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
B, function (type parameter) X in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
X, function (type parameter) E in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
R>,
options: {
readonly concurrency?: Concurrency | undefined
}
options?: { readonly concurrency?: Concurrency | undefinedconcurrency?: type Concurrency = number | "unbounded" | "inherit"Describes the concurrency level for Effect operations that run multiple
effects.
When to use
Use to type options that control how many effects may run at the same time.
Details
number — run at most N effects concurrently.
"unbounded" — run all effects concurrently with no limit.
"inherit" — inherit the concurrency from the surrounding context.
Example (Setting concurrency values)
import type { Types } from "effect"
const sequential: Types.Concurrency = 1
const limited: Types.Concurrency = 5
const unbounded: Types.Concurrency = "unbounded"
const inherit: Types.Concurrency = "inherit"
Concurrency | undefined }
): (elements: Iterable<A>elements: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
A>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<interface Array<T>Array<function (type parameter) B in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
B>, function (type parameter) E in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): (elements: Iterable<A>) => Effect<Array<B>, E, R>
R>
<function (type parameter) A in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
A, function (type parameter) B in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
B, function (type parameter) X in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
X, function (type parameter) E in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
R>(
elements: Iterable<A>elements: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
A>,
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>
filter: import FilterFilter.interface FilterEffect<in Input, out Pass, out Fail, out E = never, out R = never>Represents an effectful filter function that can produce Effects.
Details
Similar to a regular Filter, but the filtering operation itself can be
effectful, allowing for asynchronous operations, error handling, and
dependency injection.
Example (Defining an effectful user filter)
import { Effect, Filter, Result } from "effect"
// An effectful filter that validates user data
type User = { id: string; isActive: boolean }
type ValidationError = { message: string }
const validateUser: Filter.FilterEffect<
string,
User,
User,
ValidationError,
never
> = (id) =>
Effect.gen(function*() {
const user: User = { id, isActive: id.length > 0 }
return user.isActive ? Result.succeed(user) : Result.fail(user)
})
FilterEffect<type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
A>, function (type parameter) B in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
B, function (type parameter) X in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
X, function (type parameter) E in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
R>,
options: {
readonly concurrency?: Concurrency | undefined
}
options?: { readonly concurrency?: Concurrency | undefinedconcurrency?: type Concurrency = number | "unbounded" | "inherit"Describes the concurrency level for Effect operations that run multiple
effects.
When to use
Use to type options that control how many effects may run at the same time.
Details
number — run at most N effects concurrently.
"unbounded" — run all effects concurrently with no limit.
"inherit" — inherit the concurrency from the surrounding context.
Example (Setting concurrency values)
import type { Types } from "effect"
const sequential: Types.Concurrency = 1
const limited: Types.Concurrency = 5
const unbounded: Types.Concurrency = "unbounded"
const inherit: Types.Concurrency = "inherit"
Concurrency | undefined }
): interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<interface Array<T>Array<function (type parameter) B in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
B>, function (type parameter) E in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
E, function (type parameter) R in <A, B, X, E, R>(elements: Iterable<A>, filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>, options?: {
readonly concurrency?: Concurrency | undefined;
}): Effect<Array<B>, E, R>
R>
} = import internalinternal.const filterMapEffect: {
<A, B, X, E, R>(
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>,
options?: {
readonly concurrency?:
| Concurrency
| undefined
}
): (
elements: Iterable<A>
) => Effect.Effect<Array<B>, E, R>
<A, B, X, E, R>(
elements: Iterable<A>,
filter: Filter.FilterEffect<
NoInfer<A>,
B,
X,
E,
R
>,
options?: {
readonly concurrency?:
| Concurrency
| undefined
}
): Effect.Effect<Array<B>, E, R>
}
filterMapEffect