Hyperlinkv0.8.0-beta.28

Stream

Stream.provideconsteffect/Stream.ts:10031
<AL, EL = never, RL = never>(
  layer: Layer.Layer<AL, EL, RL> | Context.Context<AL>,
  options?: { readonly local?: boolean | undefined } | undefined
): <A, E, R>(
  self: Stream<A, E, R>
) => Stream<A, E | EL, Exclude<R, AL> | RL>
<A, E, R, AL, EL = never, RL = never>(
  self: Stream<A, E, R>,
  layer: Layer.Layer<AL, EL, RL> | Context.Context<AL>,
  options?: { readonly local?: boolean | undefined } | undefined
): Stream<A, E | EL, Exclude<R, AL> | RL>

Provides a layer or context to the stream, removing the corresponding service requirements. Use options.local to build the layer every time; by default, layers are shared between provide calls.

Example (Providing stream requirements)

import { Console, Context, Effect, Layer, Stream } from "effect"

class Env extends Context.Service<Env, { readonly name: string }>()("Env") {}

const layer = Layer.succeed(Env)({ name: "Ada" })

const stream = Stream.fromEffect(
  Effect.gen(function*() {
    const env = yield* Effect.service(Env)
    return `Hello, ${env.name}`
  })
)

const withEnv = stream.pipe(Stream.provide(layer))

const program = Stream.runCollect(withEnv).pipe(
  Effect.flatMap((values) => Console.log(values))
)

Effect.runPromise(program)
// Output:
// ["Hello, Ada"]
services
Source effect/Stream.ts:1003123 lines
export const provide: {
  <AL, EL = never, RL = never>(
    layer: Layer.Layer<AL, EL, RL> | Context.Context<AL>,
    options?: {
      readonly local?: boolean | undefined
    } | undefined
  ): <A, E, R>(
    self: Stream<A, E, R>
  ) => Stream<A, E | EL, Exclude<R, AL> | RL>
  <A, E, R, AL, EL = never, RL = never>(
    self: Stream<A, E, R>,
    layer: Layer.Layer<AL, EL, RL> | Context.Context<AL>,
    options?: {
      readonly local?: boolean | undefined
    } | undefined
  ): Stream<A, E | EL, Exclude<R, AL> | RL>
} = dual((args) => isStream(args[0]), <A, E, R, AL, EL = never, RL = never>(
  self: Stream<A, E, R>,
  layer: Layer.Layer<AL, EL, RL> | Context.Context<AL>,
  options?: {
    readonly local?: boolean | undefined
  } | undefined
): Stream<A, E | EL, Exclude<R, AL> | RL> => fromChannel(Channel.provide(self.channel, layer, options)))
Referenced by 1 symbols