import type * as HKT from "@principia/prelude/HKT"; import type { Option } from "../../Option"; import * as M from "../Managed"; import * as T from "../Task"; import * as XR from "../XRef"; export declare const URI = "Stream"; export declare type URI = typeof URI; export declare type V = HKT.V<"R", "-"> & HKT.V<"E", "+">; /** * A `Stream` is a description of a program that, when evaluated, * may emit 0 or more values of type `A`, may fail with errors of type `E` * and uses an environment of type `R` and can be sync or async `X`. * One way to think of `Stream` is as a `Task` program that could emit multiple values. * * This data type can emit multiple `A` values through multiple calls to `next`. * Similarly, embedded inside every `Stream` is an Task program: `Task, ReadonlyArray>`. * This program will be repeatedly evaluated as part of the stream execution. For * every evaluation, it will emit a chunk of values or end with an optional failure. * A failure of type `None` signals the end of the stream. * * `Stream` is a purely functional *pull* based stream. Pull based streams offer * inherent laziness and backpressure, relieving users of the need to manage buffers * between operatrs. As an optimization, `Stream` does not emit single values, but * rather an array of values. This allows the cost of effect evaluation to be * amortized. * * The last important attribute of `Stream` is resource management: it makes * heavy use of `Managed` to manage resources that are acquired * and released during the stream's lifetime. * * `Stream` forms a monad on its `A` type parameter, and has error management * facilities for its `E` type parameter, modeled similarly to `Task` (with some * adjustments for the multiple-valued nature of `Stream`). These aspects allow * for rich and expressive composition of streams. * * The current encoding of `Stream` is *not* safe for recursion. `Stream` programs * that are defined in terms of themselves will leak memory. * * Instead, recursive operators must be defined explicitly. See the definition of * `forever` for an example. This limitation will be lifted in the future. */ export declare class Stream { readonly proc: M.Managed, ReadonlyArray>>; readonly [T._U]: URI; readonly [T._E]: () => E; readonly [T._A]: () => A; readonly [T._R]: (_: R) => void; constructor(proc: M.Managed, ReadonlyArray>>); } /** * Type aliases */ export declare type IO = Stream; export declare type RIO = Stream; export declare type EIO = Stream; /** * The default chunk size used by the various combinators and constructors of [[Stream]]. */ export declare const DefaultChunkSize = 4096; /** * @internal */ export declare class Chain { readonly f0: (a: O) => Stream; readonly outerStream: T.Task, ReadonlyArray>; readonly currOuterChunk: XR.Ref<[ReadonlyArray, number]>; readonly currInnerStream: XR.Ref, ReadonlyArray>>; readonly innerFinalizer: XR.Ref; constructor( f0: (a: O) => Stream, outerStream: T.Task, ReadonlyArray>, currOuterChunk: XR.Ref<[ReadonlyArray, number]>, currInnerStream: XR.Ref, ReadonlyArray>>, innerFinalizer: XR.Ref ); closeInner(): T.Task; pullNonEmpty(pull: T.Task, ReadonlyArray>): T.Task, ReadonlyArray>; pullOuter(): T.Task, void>; apply(): T.Task, ReadonlyArray>; } //# sourceMappingURL=model.d.ts.map