Hyperlinkv0.8.0-beta.28

Channel

Channel.concatWithconsteffect/Channel.ts:2416
<OutDone, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(
  f: (
    leftover: Types.NoInfer<OutDone>
  ) => Channel<
    OutElem1,
    OutErr1,
    OutDone1,
    InElem1,
    InErr1,
    InDone1,
    Env1
  >
): <OutElem, OutErr, InElem, InErr, InDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>
) => Channel<
  OutElem | OutElem1,
  OutErr1 | OutErr,
  OutDone1,
  InElem & InElem1,
  InErr & InErr1,
  InDone & InDone1,
  Env1 | Env
>
<
  OutElem,
  OutErr,
  OutDone,
  InElem,
  InErr,
  InDone,
  Env,
  OutElem1,
  OutErr1,
  OutDone1,
  InElem1,
  InErr1,
  InDone1,
  Env1
>(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
  f: (
    leftover: Types.NoInfer<OutDone>
  ) => Channel<
    OutElem1,
    OutErr1,
    OutDone1,
    InElem1,
    InErr1,
    InDone1,
    Env1
  >
): Channel<
  OutElem | OutElem1,
  OutErr1 | OutErr,
  OutDone1,
  InElem & InElem1,
  InErr & InErr1,
  InDone & InDone1,
  Env1 | Env
>

Concatenates this channel with another channel created from the terminal value of this channel. The new channel is created using the provided function.

Example (Concatenating with completion values)

import { Channel, Data } from "effect"

class ConcatError extends Data.TaggedError("ConcatError")<{
  readonly reason: string
}> {}

// Create a channel that outputs numbers and terminates with sum
const numberChannel = Channel.fromIterable([1, 2, 3]).pipe(
  Channel.concatWith((sum: void) => Channel.succeed(`Completed processing`))
)

// Concatenates additional channel based on completion value
// Outputs: 1, 2, 3, then "Completed processing"
sequencing
Source effect/Channel.ts:241687 lines
export const concatWith: {
  <OutDone, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(
    f: (leftover: Types.NoInfer<OutDone>) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>
  ): <OutElem, OutErr, InElem, InErr, InDone, Env>(
    self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>
  ) => Channel<
    OutElem | OutElem1,
    OutErr1 | OutErr,
    OutDone1,
    InElem & InElem1,
    InErr & InErr1,
    InDone & InDone1,
    Env1 | Env
  >
  <
    OutElem,
    OutErr,
    OutDone,
    InElem,
    InErr,
    InDone,
    Env,
    OutElem1,
    OutErr1,
    OutDone1,
    InElem1,
    InErr1,
    InDone1,
    Env1
  >(
    self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
    f: (leftover: Types.NoInfer<OutDone>) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>
  ): Channel<
    OutElem | OutElem1,
    OutErr1 | OutErr,
    OutDone1,
    InElem & InElem1,
    InErr & InErr1,
    InDone & InDone1,
    Env1 | Env
  >
} = dual(2, <
  OutElem,
  OutErr,
  OutDone,
  InElem,
  InErr,
  InDone,
  Env,
  OutElem1,
  OutErr1,
  OutDone1,
  InElem1,
  InErr1,
  InDone1,
  Env1
>(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
  f: (leftover: Types.NoInfer<OutDone>) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>
): Channel<
  OutElem | OutElem1,
  OutErr1 | OutErr,
  OutDone1,
  InElem & InElem1,
  InErr & InErr1,
  InDone & InDone1,
  Env1 | Env
> =>
  fromTransform((upstream, scope) =>
    Effect.sync(() => {
      let currentPull: Pull.Pull<OutElem | OutElem1, OutErr1 | OutErr, OutDone1, Env1 | Env> | undefined
      const forkedScope = Scope.forkUnsafe(scope)
      const makePull = Effect.flatMap(toTransform(self)(upstream, forkedScope), (pull) => {
        currentPull = Pull.catchDone(pull, (leftover) => {
          return Scope.close(forkedScope, Exit.void).pipe(
            Effect.flatMap(() => toTransform(f(leftover as OutDone))(upstream, scope)),
            Effect.flatMap((pull) => {
              currentPull = pull
              return pull
            })
          )
        })
        return currentPull
      })
      return Effect.suspend(() => currentPull ?? makePull)
    })
  ))
Referenced by 4 symbols