Skip to content

DocStream

35 exports Added in v1.0.0 Source

Annotations

Changes the annotation of a document to a different annotation, or to none at all.

Signature

declare const alterAnnotations: {
  <A, B>(f: (a: A) => Option<B>): (self: DocStream<A>) => DocStream<B>;
  <A, B>(self: DocStream<A>, f: (a: A) => Option<B>): DocStream<B>;
};

reAnnotate

Added in v1.0.0 Source

Modify the annotations of a document.

Signature

declare const reAnnotate: {
  <A, B>(f: (a: A) => B): (self: DocStream<A>) => DocStream<B>;
  <A, B>(self: DocStream<A>, f: (a: A) => B): DocStream<B>;
};

unAnnotate

Added in v1.0.0 Source

Remove all annotations from a document.

Signature

declare const unAnnotate: <A>(self: DocStream<A>) => DocStream<never>;

Constructors

char

Added in v1.0.0 Source

Signature

declare const char: {
  (char: string): <A>(self: DocStream<A>) => DocStream<A>;
  <A>(self: DocStream<A>, char: string): DocStream<A>;
};

empty

Added in v1.0.0 Source

Signature

declare const empty: DocStream<never>;

failed

Added in v1.0.0 Source

Signature

declare const failed: DocStream<never>;

line

Added in v1.0.0 Source

Signature

declare const line: {
  (indentation: number): <A>(self: DocStream<A>) => DocStream<A>;
  <A>(self: DocStream<A>, indentation: number): DocStream<A>;
};

Signature

declare const popAnnotation: <A>(stream: DocStream<A>) => DocStream<A>;

Signature

declare const pushAnnotation: {
  <B>(annotation: B): <A>(self: DocStream<A>) => DocStream<B | A>;
  <A, B>(self: DocStream<A>, annotation: B): DocStream<A | B>;
};

text

Added in v1.0.0 Source

Signature

declare const text: {
  (text: string): <A>(self: DocStream<A>) => DocStream<A>;
  <A>(self: DocStream<A>, text: string): DocStream<A>;
};

Folding

foldMap

Added in v1.0.0 Source

Signature

declare const foldMap: {
  <A, M>(M: Monoid<M>, f: (a: A) => M): (self: DocStream<A>) => M;
  <A, M>(self: DocStream<A>, M: Monoid<M>, f: (a: A) => M): M;
};

match

Added in v1.0.0 Source

Signature

declare const match: {
  <A, R>(patterns: {
    readonly CharStream: (char: string, stream: DocStream<A>) => R;
    readonly EmptyStream: () => R;
    readonly FailedStream: () => R;
    readonly LineStream: (indentation: number, stream: DocStream<A>) => R;
    readonly PopAnnotationStream: (stream: DocStream<A>) => R;
    readonly PushAnnotationStream: (annotation: A, stream: DocStream<A>) => R;
    readonly TextStream: (text: string, stream: DocStream<A>) => R;
  }): (self: DocStream<A>) => R;
  <A, R>(
    self: DocStream<A>,
    patterns: {
      readonly CharStream: (char: string, stream: DocStream<A>) => R;
      readonly EmptyStream: () => R;
      readonly FailedStream: () => R;
      readonly LineStream: (indentation: number, stream: DocStream<A>) => R;
      readonly PopAnnotationStream: (stream: DocStream<A>) => R;
      readonly PushAnnotationStream: (annotation: A, stream: DocStream<A>) => R;
      readonly TextStream: (text: string, stream: DocStream<A>) => R;
    },
  ): R;
};

Instances

Functor

Added in v1.0.0 Source

Signature

declare const Functor: covariant.Covariant<DocStreamTypeLambda>;

Invariant

Added in v1.0.0 Source

Signature

declare const Invariant: invariant.Invariant<DocStreamTypeLambda>;

Mapping

map

Added in v1.0.0 Source

Signature

declare const map: {
  <A, B>(f: (a: A) => B): (self: DocStream<A>) => DocStream<B>;
  <A, B>(self: DocStream<A>, f: (a: A) => B): DocStream<B>;
};

Model

CharStream interface

Added in v1.0.0 Source

Represents a Doc containing a single character.

Signature

interface CharStream<A> extends Variance<A> {
  readonly _tag: "CharStream";
  readonly char: string;
  readonly stream: DocStream<A>;
}

DocStream type

Added in v1.0.0 Source

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.

Signature

type DocStream<A> =
  | FailedStream<A>
  | EmptyStream<A>
  | CharStream<A>
  | TextStream<A>
  | LineStream<A>
  | PushAnnotationStream<A>
  | PopAnnotationStream<A>;

DocStreamTypeLambda interface

Added in v1.0.0 Source

Signature

interface DocStreamTypeLambda extends TypeLambda {
  readonly type: DocStream<unknown>;
}

EmptyStream interface

Added in v1.0.0 Source

Represents the an empty Doc.

Signature

interface EmptyStream<A> extends Variance<A> {
  readonly _tag: "EmptyStream";
}

FailedStream interface

Added in v1.0.0 Source

Represents a Doc that failed to be laid out.

Signature

interface FailedStream<A> extends Variance<A> {
  readonly _tag: "FailedStream";
}

LineStream interface

Added in v1.0.0 Source

Represents a Doc containing a single line. The indentation represents the indentation level for the subsequent line in the Doc.

Signature

interface LineStream<A> extends Variance<A> {
  readonly _tag: "LineStream";
  readonly indentation: number;
  readonly stream: DocStream<A>;
}

PopAnnotationStream interface

Added in v1.0.0 Source

Represents the removal of a previously pushed annotation from a Doc.

Signature

interface PopAnnotationStream<A> extends Variance<A> {
  readonly _tag: "PopAnnotationStream";
  readonly stream: DocStream<A>;
}

PushAnnotationStream interface

Added in v1.0.0 Source

Represents the addition of an annotation of type A to a Doc.

Signature

interface PushAnnotationStream<A> extends Variance<A> {
  readonly _tag: "PushAnnotationStream";
  readonly annotation: A;
  readonly stream: DocStream<A>;
}

TextStream interface

Added in v1.0.0 Source

Represents a Doc containing a string of text.

Signature

interface TextStream<A> extends Variance<A> {
  readonly _tag: "TextStream";
  readonly stream: DocStream<A>;
  readonly text: string;
}

Other

DocStream

Added in v1.0.0 Source

Refinements

isCharStream

Added in v1.0.0 Source

Returns true if the specified DocStream is a CharStream, false otherwise.

Signature

declare const isCharStream: <A>(self: DocStream<A>) => self is CharStream<A>;

isDocStream

Added in v1.0.0 Source

Returns true if the specified value is a DocStream, false otherwise.

Signature

declare const isDocStream: (u: unknown) => u is DocStream<unknown>;

Returns true if the specified DocStream is a EmptyStream, false otherwise.

Signature

declare const isEmptyStream: <A>(self: DocStream<A>) => self is EmptyStream<A>;

Returns true if the specified DocStream is a FailedStream, false otherwise.

Signature

declare const isFailedStream: <A>(self: DocStream<A>) => self is FailedStream<A>;

isLineStream

Added in v1.0.0 Source

Returns true if the specified DocStream is a LineStream, false otherwise.

Signature

declare const isLineStream: <A>(self: DocStream<A>) => self is LineStream<A>;

Returns true if the specified DocStream is a PopAnnotationStream, false otherwise.

Signature

declare const isPopAnnotationStream: <A>(self: DocStream<A>) => self is PopAnnotationStream<A>;

Returns true if the specified DocStream is a PushAnnotationStream, false otherwise.

Signature

declare const isPushAnnotationStream: <A>(self: DocStream<A>) => self is PushAnnotationStream<A>;

isTextStream

Added in v1.0.0 Source

Returns true if the specified DocStream is a TextStream, false otherwise.

Signature

declare const isTextStream: <A>(self: DocStream<A>) => self is TextStream<A>;

Symbol

Signature

declare const DocStreamTypeId: unique symbol;

DocStreamTypeId type

Added in v1.0.0 Source

Signature

type DocStreamTypeId = typeof DocStreamTypeId;