Thanks to visit codestin.com
Credit goes to effect-ts.github.io

Skip to main content Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

DocTree.ts overview

Since v1.0.0


Exports Grouped by Category


annotations

alterAnnotations

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

Signature

declare const alterAnnotations: {
  <A, B>(f: (a: A) => Iterable<B>): (self: DocTree<A>) => DocTree<B>
  <A, B>(self: DocTree<A>, f: (a: A) => Iterable<B>): DocTree<B>
}

Source

Since v1.0.0

reAnnotate

Change the annotation of a DocTree.

Signature

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

Source

Since v1.0.0

unAnnotate

Remove all annotations from a DocTree.

Signature

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

Source

Since v1.0.0

constructors

annotation

Annotate the specified DocTree with an annotation of type A.

Signature

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

Source

Since v1.0.0

char

Signature

declare const char: <A>(char: string) => DocTree<A>

Source

Since v1.0.0

concat

Horizontally concatenates multiple DocTrees.

Signature

declare const concat: <A>(trees: ReadonlyArray<DocTree<A>>) => DocTree<A>

Source

Since v1.0.0

empty

Signature

declare const empty: DocTree<never>

Source

Since v1.0.0

line

Signature

declare const line: <A>(indentation: number) => DocTree<A>

Source

Since v1.0.0

text

Signature

declare const text: <A>(text: string) => DocTree<A>

Source

Since v1.0.0

conversions

treeForm

Converts a DocStream<A> into a DocTree<A>.

Signature

declare const treeForm: <A>(stream: DocStream.DocStream<A>) => DocTree<A>

Source

Since v1.0.0

folding

foldMap

Signature

declare const foldMap: {
  <A, M>(M: monoid.Monoid<M>, f: (a: A) => M): (self: DocTree<A>) => M
  <A, M>(self: DocTree<A>, M: monoid.Monoid<M>, f: (a: A) => M): M
}

Source

Since v1.0.0

instances

Covariant

Signature

declare const Covariant: covariant.Covariant<DocTreeTypeLambda>

Source

Since v1.0.0

Invariant

Signature

declare const Invariant: invariant.Invariant<DocTreeTypeLambda>

Source

Since v1.0.0

getMonoid

Signature

declare const getMonoid: <A>(_: void) => monoid.Monoid<DocTree<A>>

Source

Since v1.0.0

getSemigroup

Signature

declare const getSemigroup: <A>(_: void) => semigroup.Semigroup<DocTree<A>>

Source

Since v1.0.0

model

AnnotationTree (interface)

Signature

export interface AnnotationTree<A> extends DocTree.Variance<A> {
  readonly _tag: "AnnotationTree"
  readonly annotation: A
  readonly tree: DocTree<A>
}

Source

Since v1.0.0

CharTree (interface)

Signature

export interface CharTree<A> extends DocTree.Variance<A> {
  readonly _tag: "CharTree"
  readonly char: string
}

Source

Since v1.0.0

ConcatTree (interface)

Signature

export interface ConcatTree<A> extends DocTree.Variance<A> {
  readonly _tag: "ConcatTree"
  readonly trees: ReadonlyArray<DocTree<A>>
}

Source

Since v1.0.0

DocTree (type alias)

Represents a document that has been laid out into a tree-like structure.

A DocStream is a linked list of different annotated cons cells (i.e. TextStream and then some further DocStream, LineStream and then some further DocStream, etc.). The DocStream format is quite suitable as a target for a layout engine, but is not suitable for rendering to a more structured format, such as HTML, where we do not want to perform a lookahead until the end of some pre-defined markup. These formats would benefit more from a tree-like structure that explicitly marks its contents as annotated. A DocTree is therefore much more suitable for this use case.

Signature

type DocTree<A> = EmptyTree<A> | CharTree<A> | TextTree<A> | LineTree<A> | AnnotationTree<A> | ConcatTree<A>

Source

Since v1.0.0

DocTreeTypeLambda (interface)

Signature

export interface DocTreeTypeLambda extends TypeLambda {
  readonly type: DocTree<this["Target"]>
}

Source

Since v1.0.0

EmptyTree (interface)

Signature

export interface EmptyTree<A> extends DocTree.Variance<A> {
  readonly _tag: "EmptyTree"
}

Source

Since v1.0.0

LineTree (interface)

Signature

export interface LineTree<A> extends DocTree.Variance<A> {
  readonly _tag: "LineTree"
  readonly indentation: number
}

Source

Since v1.0.0

TextTree (interface)

Signature

export interface TextTree<A> extends DocTree.Variance<A> {
  readonly _tag: "TextTree"
  readonly text: string
}

Source

Since v1.0.0

refinements

isAnnotationTree

Returns true if the specified DocTree is an AnnotationTree, false otherwise.

Signature

declare const isAnnotationTree: <A>(self: DocTree<A>) => self is AnnotationTree<A>

Source

Since v1.0.0

isCharTree

Returns true if the specified DocTree is an CharTree, false otherwise.

Signature

declare const isCharTree: <A>(self: DocTree<A>) => self is CharTree<A>

Source

Since v1.0.0

isConcatTree

Returns true if the specified DocTree is an ConcatTree, false otherwise.

Signature

declare const isConcatTree: <A>(self: DocTree<A>) => self is ConcatTree<A>

Source

Since v1.0.0

isDocTree

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

Signature

declare const isDocTree: (u: unknown) => u is DocTree<unknown>

Source

Since v1.0.0

isEmptyTree

Returns true if the specified DocTree is an EmptyTree, false otherwise.

Signature

declare const isEmptyTree: <A>(self: DocTree<A>) => self is EmptyTree<A>

Source

Since v1.0.0

isLineTree

Returns true if the specified DocTree is an LineTree, false otherwise.

Signature

declare const isLineTree: <A>(self: DocTree<A>) => self is LineTree<A>

Source

Since v1.0.0

isTextTree

Returns true if the specified DocTree is an TextTree, false otherwise.

Signature

declare const isTextTree: <A>(self: DocTree<A>) => self is TextTree<A>

Source

Since v1.0.0

rendering

renderSimplyDecorated

The simplest possible tree-based renderer.

For example, here is a document annotated with void and thee behavior is to surround annotated regions with »»>« and »«<«.

Example

import * as assert from "node:assert"
import * as Doc from "@effect/printer/Doc"
import * as DocTree from "@effect/printer/DocTree"
import * as Layout from "@effect/printer/Layout"
import { identity, pipe } from "effect/Function"
import * as String from "@effect/typeclass/data/String"

const doc: Doc.Doc<void> = Doc.hsep([
  Doc.text("hello"),
  pipe(Doc.text("world"), Doc.annotate(undefined), Doc.cat(Doc.char("!")))
])

const tree = DocTree.treeForm(Layout.pretty(Layout.defaultOptions)(doc))

const rendered = pipe(
  tree,
  DocTree.renderSimplyDecorated(String.Monoid, identity, (_, x) => `>>>${x}<<<`)
)

assert.strictEqual(rendered, "hello >>>world<<<!")

Signature

declare const renderSimplyDecorated: {
  <A, M>(
    M: monoid.Monoid<M>,
    renderText: (text: string) => M,
    renderAnnotation: (annotation: A, out: M) => M
  ): (self: DocTree<A>) => M
  <A, M>(
    self: DocTree<A>,
    M: monoid.Monoid<M>,
    renderText: (text: string) => M,
    renderAnnotation: (annotation: A, out: M) => M
  ): M
}

Source

Since v1.0.0

symbol

DocTreeTypeId

Signature

declare const DocTreeTypeId: unique symbol

Source

Since v1.0.0

DocTreeTypeId (type alias)

Signature

type DocTreeTypeId = typeof DocTreeTypeId

Source

Since v1.0.0

utils

DocTree (namespace)

Source

Since v1.0.0

Variance (interface)

Signature

export interface Variance<A> extends Equal {
  readonly [DocTreeTypeId]: {
    readonly _A: (_: never) => A
  }
}

Source

Since v1.0.0

TypeLambda (type alias)

Signature

type TypeLambda = DocTreeTypeLambda

Source

Since v1.0.0