/** * @since 1.0.0 */ import type * as covariant from "@effect/typeclass/Covariant" import type * as invariant from "@effect/typeclass/Invariant" import type * as monoid from "@effect/typeclass/Monoid" import type { Equal } from "effect/Equal" import type { TypeLambda } from "effect/HKT" import type { Option } from "effect/Option" import * as internal from "./internal/docStream.js" // ----------------------------------------------------------------------------- // Models // ----------------------------------------------------------------------------- /** * @since 1.0.0 * @category symbol */ export const DocStreamTypeId: unique symbol = internal.DocStreamTypeId as DocStreamTypeId /** * @since 1.0.0 * @category symbol */ export type DocStreamTypeId = typeof DocStreamTypeId /** * Represents a document that has been laid out and can be processed used by the * rendering algorithms. * * A simplified view is that a `Doc` is equivalent to an array of `DocStream`, * and the layout algorithms simply pick a `DocStream` based upon which instance * best fits the layout constraints. Therefore, a `DocStream` has all complexity * contained in a `Doc` resolved, making it very easy to convert to other * formats, such as plaintext or terminal output. * * @since 1.0.0 * @category model */ export type DocStream = | FailedStream | EmptyStream | CharStream | TextStream | LineStream | PushAnnotationStream | PopAnnotationStream /** * @since 1.0.0 */ export declare namespace DocStream { /** * @since 1.0.0 * @category model */ export interface Variance extends Equal { readonly [DocStreamTypeId]: { readonly _A: (_: never) => A } } /** * @since 1.0.0 * @category model */ export type TypeLambda = DocStreamTypeLambda } /** * @since 1.0.0 * @category model */ export interface DocStreamTypeLambda extends TypeLambda { readonly type: DocStream } /** * Represents a `Doc` that failed to be laid out. * * @since 1.0.0 * @category model */ export interface FailedStream extends DocStream.Variance { readonly _tag: "FailedStream" } /** * Represents the an empty `Doc`. * * @since 1.0.0 * @category model */ export interface EmptyStream extends DocStream.Variance { readonly _tag: "EmptyStream" } /** * Represents a `Doc` containing a single character. * * @since 1.0.0 * @category model */ export interface CharStream extends DocStream.Variance { readonly _tag: "CharStream" readonly char: string readonly stream: DocStream } /** * Represents a `Doc` containing a string of text. * * @since 1.0.0 * @category model */ export interface TextStream extends DocStream.Variance { readonly _tag: "TextStream" readonly text: string readonly stream: DocStream } /** * Represents a `Doc` containing a single line. The `indentation` * represents the indentation level for the subsequent line in the * `Doc`. * * @since 1.0.0 * @category model */ export interface LineStream extends DocStream.Variance { readonly _tag: "LineStream" readonly indentation: number readonly stream: DocStream } /** * Represents the addition of an annotation of type `A` to a `Doc`. * * @since 1.0.0 * @category model */ export interface PushAnnotationStream extends DocStream.Variance { readonly _tag: "PushAnnotationStream" readonly annotation: A readonly stream: DocStream } /** * Represents the removal of a previously pushed annotation from a `Doc`. * * @since 1.0.0 * @category model */ export interface PopAnnotationStream extends DocStream.Variance { readonly _tag: "PopAnnotationStream" readonly stream: DocStream } // ----------------------------------------------------------------------------- // Refinements // ----------------------------------------------------------------------------- /** * Returns `true` if the specified value is a `DocStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isDocStream: (u: unknown) => u is DocStream = internal.isDocStream /** * Returns `true` if the specified `DocStream` is a `FailedStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isFailedStream: (self: DocStream) => self is FailedStream = internal.isFailedStream /** * Returns `true` if the specified `DocStream` is a `EmptyStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isEmptyStream: (self: DocStream) => self is EmptyStream = internal.isEmptyStream /** * Returns `true` if the specified `DocStream` is a `CharStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isCharStream: (self: DocStream) => self is CharStream = internal.isCharStream /** * Returns `true` if the specified `DocStream` is a `TextStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isTextStream: (self: DocStream) => self is TextStream = internal.isTextStream /** * Returns `true` if the specified `DocStream` is a `LineStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isLineStream: (self: DocStream) => self is LineStream = internal.isLineStream /** * Returns `true` if the specified `DocStream` is a `PushAnnotationStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isPushAnnotationStream: ( self: DocStream ) => self is PushAnnotationStream = internal.isPushAnnotationStream /** * Returns `true` if the specified `DocStream` is a `PopAnnotationStream`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isPopAnnotationStream: ( self: DocStream ) => self is PopAnnotationStream = internal.isPopAnnotationStream // ----------------------------------------------------------------------------- // Constructors // ----------------------------------------------------------------------------- /** * @since 1.0.0 * @category constructors */ export const failed: DocStream = internal.failed /** * @since 1.0.0 * @category constructors */ export const empty: DocStream = internal.empty /** * @since 1.0.0 * @category constructors */ export const char: { /** * @since 1.0.0 * @category constructors */ (char: string): (self: DocStream) => DocStream /** * @since 1.0.0 * @category constructors */ (self: DocStream, char: string): DocStream } = internal.char /** * @since 1.0.0 * @category constructors */ export const text: { /** * @since 1.0.0 * @category constructors */ (text: string): (self: DocStream) => DocStream /** * @since 1.0.0 * @category constructors */ (self: DocStream, text: string): DocStream } = internal.text /** * @since 1.0.0 * @category constructors */ export const line: { /** * @since 1.0.0 * @category constructors */ (indentation: number): (self: DocStream) => DocStream /** * @since 1.0.0 * @category constructors */ (self: DocStream, indentation: number): DocStream } = internal.line /** * @since 1.0.0 * @category constructors */ export const pushAnnotation: { /** * @since 1.0.0 * @category constructors */ (annotation: B): (self: DocStream) => DocStream /** * @since 1.0.0 * @category constructors */ (self: DocStream, annotation: B): DocStream } = internal.pushAnnotation /** * @since 1.0.0 * @category constructors */ export const popAnnotation: (stream: DocStream) => DocStream = internal.popAnnotation // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * Changes the annotation of a document to a different annotation, or to * none at all. * * @since 1.0.0 * @category annotations */ export const alterAnnotations: { // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * Changes the annotation of a document to a different annotation, or to * none at all. * * @since 1.0.0 * @category annotations */ (f: (a: A) => Option): (self: DocStream) => DocStream // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * Changes the annotation of a document to a different annotation, or to * none at all. * * @since 1.0.0 * @category annotations */ (self: DocStream, f: (a: A) => Option): DocStream } = internal.alterAnnotations /** * Modify the annotations of a document. * * @since 1.0.0 * @category annotations */ export const reAnnotate: { /** * Modify the annotations of a document. * * @since 1.0.0 * @category annotations */ (f: (a: A) => B): (self: DocStream) => DocStream /** * Modify the annotations of a document. * * @since 1.0.0 * @category annotations */ (self: DocStream, f: (a: A) => B): DocStream } = internal.reAnnotate /** * Remove all annotations from a document. * * @since 1.0.0 * @category annotations */ export const unAnnotate: (self: DocStream) => DocStream = internal.unAnnotate // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * @since 1.0.0 * @category folding */ export const foldMap: { // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * @since 1.0.0 * @category folding */ (M: monoid.Monoid, f: (a: A) => M): (self: DocStream) => M // ----------------------------------------------------------------------------- // Annotations // ----------------------------------------------------------------------------- /** * @since 1.0.0 * @category folding */ (self: DocStream, M: monoid.Monoid, f: (a: A) => M): M } = internal.foldMap /** * @since 1.0.0 * @category folding */ export const match: { /** * @since 1.0.0 * @category folding */ ( patterns: { readonly FailedStream: () => R readonly EmptyStream: () => R readonly CharStream: (char: string, stream: DocStream) => R readonly TextStream: (text: string, stream: DocStream) => R readonly LineStream: (indentation: number, stream: DocStream) => R readonly PushAnnotationStream: (annotation: A, stream: DocStream) => R readonly PopAnnotationStream: (stream: DocStream) => R } ): (self: DocStream) => R /** * @since 1.0.0 * @category folding */ ( self: DocStream, patterns: { readonly FailedStream: () => R readonly EmptyStream: () => R readonly CharStream: (char: string, stream: DocStream) => R readonly TextStream: (text: string, stream: DocStream) => R readonly LineStream: (indentation: number, stream: DocStream) => R readonly PushAnnotationStream: (annotation: A, stream: DocStream) => R readonly PopAnnotationStream: (stream: DocStream) => R } ): R } = internal.match /** * @since 1.0.0 * @category mapping */ export const map: { /** * @since 1.0.0 * @category mapping */ (f: (a: A) => B): (self: DocStream) => DocStream /** * @since 1.0.0 * @category mapping */ (self: DocStream, f: (a: A) => B): DocStream } = internal.map /** * @since 1.0.0 * @category instances */ export const Functor: covariant.Covariant = internal.Covariant /** * @since 1.0.0 * @category instances */ export const Invariant: invariant.Invariant = internal.Invariant