MCPcopy Create free account
hub / github.com/effect-app/libs / flatMapSequential

Function flatMapSequential

repos/effect/packages/effect/src/Channel.ts:2302–2357  ·  view source on GitHub ↗
(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
  f: (d: OutElem) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>
)

Source from the content-addressed store, hash-verified

2300 * const observed = [await Effect.runPromise(Channel.runCollect(tappedChannel)), processed] // => [[1, 2, 3], [1, 2, 3]]
2301 * ```
2302 *
2303 * @category sequencing
2304 * @since 4.0.0
2305 */
2306export const tap: {
2307 <OutElem, X, OutErr1, Env1>(
2308 f: (d: Types.NoInfer<OutElem>) => Effect.Effect<X, OutErr1, Env1>,
2309 options?: {
2310 readonly concurrency?: number | "unbounded" | undefined
2311 }
2312 ): <OutErr, OutDone, InElem, InErr, InDone, Env>(
2313 self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>
2314 ) => Channel<OutElem, OutErr1 | OutErr, OutDone, InElem, InErr, InDone, Env1 | Env>
2315 <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, X, OutErr1, Env1>(
2316 self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
2317 f: (d: Types.NoInfer<OutElem>) => Effect.Effect<X, OutErr1, Env1>,
2318 options?: {
2319 readonly concurrency?: number | "unbounded" | undefined
2320 }
2321 ): Channel<OutElem, OutErr | OutErr1, OutDone, InElem, InErr, InDone, Env | Env1>
2322} = dual(
2323 (args) => isChannel(args[0]),
2324 <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, X, OutErr1, Env1>(
2325 self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
2326 f: (d: Types.NoInfer<OutElem>) => Effect.Effect<X, OutErr1, Env1>,
2327 options?: {
2328 readonly concurrency?: number | "unbounded" | undefined
2329 }
2330 ): Channel<OutElem, OutErr | OutErr1, OutDone, InElem, InErr, InDone, Env | Env1> =>
2331 mapEffect(self, (a) => Effect.as(f(a), a), options)
2332)
2333
2334/**
2335 * Maps each output element to a channel and flattens the child channel
2336 * outputs.
2337 *
2338 * **Details**
2339 *
2340 * The source channel's done value is preserved. Child channel done values are
2341 * used only for child-channel completion. By default child channels are run
2342 * sequentially. Use `options.concurrency` and `options.bufferSize` to run child
2343 * channels concurrently.
2344 *
2345 * **Example** (Flat mapping channel output)
2346 *
2347 * ```ts import.meta.vitest
2348 * import { Channel, Data, Effect } from "effect"
2349 *
2350 * class ProcessError extends Data.TaggedError("ProcessError")<{
2351 * readonly cause: string
2352 * }> {}
2353 *
2354 * // Create a channel that outputs numbers
2355 * const numberChannel = Channel.fromIterable([1, 2, 3])
2356 *
2357 * // FlatMap each number to create new channels
2358 * const flatMappedChannel = Channel.flatMap(
2359 * numberChannel,

Callers 1

Channel.tsFile · 0.85

Calls 5

toTransformFunction · 0.85
closeMethod · 0.80
fromTransformFunction · 0.70
mapMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…