/** * @since 2.0.0 */ import type * as Cause from "./Cause.js" import type * as Chunk from "./Chunk.js" import type * as Effect from "./Effect.js" import type * as Exit from "./Exit.js" import * as internal from "./internal/take.js" import type * as Option from "./Option.js" import type { Pipeable } from "./Pipeable.js" import type * as Types from "./Types.js" /** * @since 2.0.0 * @category symbols */ export const TakeTypeId: unique symbol = internal.TakeTypeId /** * @since 2.0.0 * @category symbols */ export type TakeTypeId = typeof TakeTypeId /** * A `Take` represents a single `take` from a queue modeling a stream of * values. A `Take` may be a failure cause `Cause`, a chunk value `Chunk`, * or an end-of-stream marker. * * @since 2.0.0 * @category models */ export interface Take extends Take.Variance, Pipeable { /** @internal */ readonly exit: Exit.Exit, Option.Option> } /** * @since 2.0.0 */ export declare namespace Take { /** * @since 2.0.0 * @category models */ export interface Variance { readonly [TakeTypeId]: { readonly _A: Types.Covariant readonly _E: Types.Covariant } } } /** * Creates a `Take` with the specified chunk. * * @since 2.0.0 * @category constructors */ export const chunk: (chunk: Chunk.Chunk) => Take = internal.chunk /** * Creates a failing `Take` with the specified defect. * * @since 2.0.0 * @category constructors */ export const die: (defect: unknown) => Take = internal.die /** * Creates a failing `Take` with the specified error message. * * @since 2.0.0 * @category constructors */ export const dieMessage: (message: string) => Take = internal.dieMessage /** * Transforms a `Take` to an `Effect`. * * @since 2.0.0 * @category destructors */ export const done: (self: Take) => Effect.Effect, Option.Option> = internal.done /** * Represents the end-of-stream marker. * * @since 2.0.0 * @category constructors */ export const end: Take = internal.end /** * Creates a failing `Take` with the specified error. * * @since 2.0.0 * @category constructors */ export const fail: (error: E) => Take = internal.fail /** * Creates a failing `Take` with the specified cause. * * @since 2.0.0 * @category constructors */ export const failCause: (cause: Cause.Cause) => Take = internal.failCause /** * Creates an effect from `Effect` that does not fail, but succeeds with * the `Take`. Error from stream when pulling is converted to * `Take.failCause`. Creates a single value chunk. * * @since 2.0.0 * @category constructors */ export const fromEffect: (effect: Effect.Effect) => Effect.Effect, never, R> = internal.fromEffect /** * Creates a `Take` from an `Exit`. * * @since 2.0.0 * @category constructors */ export const fromExit: (exit: Exit.Exit) => Take = internal.fromExit /** * Creates effect from `Effect, Option, R>` that does not fail, but * succeeds with the `Take`. Errors from stream when pulling are converted * to `Take.failCause`, and the end-of-stream is converted to `Take.end`. * * @since 2.0.0 * @category constructors */ export const fromPull: ( pull: Effect.Effect, Option.Option, R> ) => Effect.Effect, never, R> = internal.fromPull /** * Checks if this `take` is done (`Take.end`). * * @since 2.0.0 * @category getters */ export const isDone: (self: Take) => boolean = internal.isDone /** * Checks if this `take` is a failure. * * @since 2.0.0 * @category getters */ export const isFailure: (self: Take) => boolean = internal.isFailure /** * Checks if this `take` is a success. * * @since 2.0.0 * @category getters */ export const isSuccess: (self: Take) => boolean = internal.isSuccess /** * Constructs a `Take`. * * @since 2.0.0 * @category constructors */ export const make: (exit: Exit.Exit, Option.Option>) => Take = internal.make /** * Transforms `Take` to `Take` by applying function `f`. * * @since 2.0.0 * @category mapping */ export const map: { /** * Transforms `Take` to `Take` by applying function `f`. * * @since 2.0.0 * @category mapping */ (f: (a: A) => B): (self: Take) => Take /** * Transforms `Take` to `Take` by applying function `f`. * * @since 2.0.0 * @category mapping */ (self: Take, f: (a: A) => B): Take } = internal.map /** * Folds over the failure cause, success value and end-of-stream marker to * yield a value. * * @since 2.0.0 * @category destructors */ export const match: { /** * Folds over the failure cause, success value and end-of-stream marker to * yield a value. * * @since 2.0.0 * @category destructors */ ( options: { readonly onEnd: () => Z readonly onFailure: (cause: Cause.Cause) => Z2 readonly onSuccess: (chunk: Chunk.Chunk) => Z3 } ): (self: Take) => Z | Z2 | Z3 /** * Folds over the failure cause, success value and end-of-stream marker to * yield a value. * * @since 2.0.0 * @category destructors */ ( self: Take, options: { readonly onEnd: () => Z readonly onFailure: (cause: Cause.Cause) => Z2 readonly onSuccess: (chunk: Chunk.Chunk) => Z3 } ): Z | Z2 | Z3 } = internal.match /** * Effectful version of `Take.fold`. * * Folds over the failure cause, success value and end-of-stream marker to * yield an effect. * * @since 2.0.0 * @category destructors */ export const matchEffect: { /** * Effectful version of `Take.fold`. * * Folds over the failure cause, success value and end-of-stream marker to * yield an effect. * * @since 2.0.0 * @category destructors */ ( options: { readonly onEnd: Effect.Effect readonly onFailure: (cause: Cause.Cause) => Effect.Effect readonly onSuccess: (chunk: Chunk.Chunk) => Effect.Effect } ): (self: Take) => Effect.Effect /** * Effectful version of `Take.fold`. * * Folds over the failure cause, success value and end-of-stream marker to * yield an effect. * * @since 2.0.0 * @category destructors */ ( self: Take, options: { readonly onEnd: Effect.Effect readonly onFailure: (cause: Cause.Cause) => Effect.Effect readonly onSuccess: (chunk: Chunk.Chunk) => Effect.Effect } ): Effect.Effect } = internal.matchEffect /** * Creates a `Take` with a single value chunk. * * @since 2.0.0 * @category constructors */ export const of: (value: A) => Take = internal.of /** * Returns an effect that effectfully "peeks" at the success of this take. * * @since 2.0.0 * @category sequencing */ export const tap: { /** * Returns an effect that effectfully "peeks" at the success of this take. * * @since 2.0.0 * @category sequencing */ (f: (chunk: Chunk.Chunk) => Effect.Effect): (self: Take) => Effect.Effect /** * Returns an effect that effectfully "peeks" at the success of this take. * * @since 2.0.0 * @category sequencing */ (self: Take, f: (chunk: Chunk.Chunk) => Effect.Effect): Effect.Effect } = internal.tap