Hyperlinkv0.8.0-beta.28

Channel

Channel.unwrapconsteffect/Channel.ts:6626
<OutElem, OutErr, OutDone, InElem, InErr, InDone, R2, E, R>(
  channel: Effect.Effect<
    Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, R2>,
    E,
    R
  >
): Channel<
  OutElem,
  E | OutErr,
  OutDone,
  InElem,
  InErr,
  InDone,
  Exclude<R, Scope.Scope> | R2
>

Constructs a Channel from a scoped effect that will result in a Channel if successful.

Example (Unwrapping channel effects)

import { Channel, Data, Effect } from "effect"

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

// Create an effect that produces a channel
const channelEffect = Effect.succeed(
  Channel.fromIterable([1, 2, 3])
)

// Unwrap the effect to get the channel
const unwrappedChannel = Channel.unwrap(channelEffect)

// The resulting channel outputs: 1, 2, 3
constructors
Source effect/Channel.ts:662614 lines
export const unwrap = <OutElem, OutErr, OutDone, InElem, InErr, InDone, R2, E, R>(
  channel: Effect.Effect<Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, R2>, E, R>
): Channel<OutElem, E | OutErr, OutDone, InElem, InErr, InDone, Exclude<R, Scope.Scope> | R2> =>
  fromTransform((upstream, scope) => {
    let pull: Pull.Pull<OutElem, E | OutErr, OutDone> | undefined
    return Effect.succeed(Effect.suspend(() => {
      if (pull) return pull
      return channel.pipe(
        Scope.provide(scope),
        Effect.flatMap((channel) => toTransform(channel)(upstream, scope)),
        Effect.flatMap((pull_) => pull = pull_)
      )
    }))
  })
Referenced by 9 symbols