(interval: Duration.Input): Stream<void>Creates a stream that emits void immediately once, then emits another
void after each specified interval.
Example (Emitting ticks on an interval)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const ticks = yield* Stream.tick("200 millis").pipe(
Stream.take(3),
Stream.runCollect
)
yield* Console.log(ticks)
})
Effect.runPromise(program)
// Output: [ undefined, undefined, undefined ]export const const tick: (
interval: Duration.Input
) => Stream<void>
Creates a stream that emits void immediately once, then emits another
void after each specified interval.
Example (Emitting ticks on an interval)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const ticks = yield* Stream.tick("200 millis").pipe(
Stream.take(3),
Stream.runCollect
)
yield* Console.log(ticks)
})
Effect.runPromise(program)
// Output: [ undefined, undefined, undefined ]
tick = (interval: Duration.Inputinterval: import DurationDuration.type Duration.Input = /*unresolved*/ anyInput): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<void> =>
const fromPull: <A, E, R, EX, RX>(
pull: Effect.Effect<
Pull.Pull<
Arr.NonEmptyReadonlyArray<A>,
E,
void,
R
>,
EX,
RX
>
) => Stream<A, Pull.ExcludeDone<E> | EX, R | RX>
Creates a stream from a pull effect, such as one produced by Stream.toPull.
Details
A pull effect yields chunks on demand and completes when the upstream stream ends.
See Stream.toPull for a matching producer.
Example (Creating a stream from a pull effect)
import { Console, Effect, Stream } from "effect"
const program = Effect.scoped(
Effect.gen(function*() {
const source = Stream.make(1, 2, 3)
const pull = yield* Stream.toPull(source)
const stream = Stream.fromPull(Effect.succeed(pull))
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
)
Effect.runPromise(program)
// Output: [1, 2, 3]
fromPull(import EffectEffect.sync(() => {
let let first: booleanfirst = true
const const effect: Effect.Effect<
[void, ...void[]],
never,
never
>
const effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect = import EffectEffect.succeed(import ArrArr.of<void>(var undefinedundefined))
const const delayed: Effect.Effect<
[void, ...void[]],
never,
never
>
const delayed: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
delayed = import EffectEffect.delay(const effect: Effect.Effect<
[void, ...void[]],
never,
never
>
const effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect, interval: Duration.Inputinterval)
return import EffectEffect.suspend(() => {
if (let first: booleanfirst) {
let first: booleanfirst = false
return const effect: Effect.Effect<
[void, ...void[]],
never,
never
>
const effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect
}
return const delayed: Effect.Effect<
[void, ...void[]],
never,
never
>
const delayed: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
delayed
})
}))