Langium - v4.0.0
    Preparing search index...

    Function joinToNode

    • Joins the elements of the given iterable of pre-computed instances of Generated by appending the results to a CompositeGeneratorNode being returned finally. Each individual element is tested to be a string, a CompositeGeneratorNode, or undefined and included as is if that test is satisfied. Otherwise the result of applying String (string constructor) to the element is included.

      Note: empty strings being included in iterable are treated as ordinary string representations, while the value of undefined makes this function to ignore the corresponding item and no separator is appended, if configured.

      Examples:

        expandToNode`
      ${ joinToNode(['a', 'b'], { appendNewLineIfNotEmpty: true }) }

      ${ joinToNode(new Set(['a', undefined, getElementNode()]), { separator: ',', appendNewLineIfNotEmpty: true }) }
      `

      Type Parameters

      • Generated

      Parameters

      • iterable: Iterable<Generated, any, any> | Generated[]

        an Array or Iterable providing the elements to be joined

      • Optionaloptions: JoinOptions<Generated, Generated>

        optional config object for defining a separator, contributing specialized prefix and/or suffix providers, and activating conditional line-break insertion. In addition, a dedicated filter function can be provided that enables the provision of the original element indices to the aforementioned functions, if the list is to be filtered. If Array.filter would be applied to the original list, the indices will be those of the filtered list during subsequent processing that in particular will cause confusion when using the tracing variant of this function named (joinTracedToNode).

      Returns undefined | CompositeGeneratorNode

      the resulting CompositeGeneratorNode representing iterable's content

    • Joins the elements of the given iterable by applying toGenerated to each element and appending the results to a CompositeGeneratorNode being returned finally.

      Note: empty strings being returned by toGenerated are treated as ordinary string representations, while the result of undefined makes this function to ignore the corresponding item and no separator is appended, if configured.

      Examples:

        expandToNode`
      ${ joinToNode(['a', 'b'], String, { appendNewLineIfNotEmpty: true }) }

      ${ joinToNode(new Set(['a', undefined, 'b']), e => e && String(e), { separator: ',', appendNewLineIfNotEmpty: true }) }
      `

      Type Parameters

      • T

      Parameters

      • iterable: Iterable<T, any, any> | T[]

        an Array or Iterable providing the elements to be joined

      • OptionaltoGenerated: (element: T, index: number, isLast: boolean) => Generated

        a callback converting each individual element to a string, a CompositeGeneratorNode, or to undefined if to be omitted, defaults to the identity for strings, generator nodes, and undefined, and to String otherwise.

      • Optionaloptions: JoinOptions<T, T>

        optional config object for defining a separator, contributing specialized prefix and/or suffix providers, and activating conditional line-break insertion. In addition, a dedicated filter function can be provided that enables the provision of the original element indices to the aforementioned functions, if the list is to be filtered. If Array.filter would be applied to the original list, the indices will be those of the filtered list during subsequent processing that in particular will cause confusion when using the tracing variant of this function named (joinTracedToNode).

      Returns undefined | CompositeGeneratorNode

      the resulting CompositeGeneratorNode representing iterable's content

    • Joins the elements of the given iterable by applying toGenerated to each element and appending the results to a CompositeGeneratorNode being returned finally.

      Here the mandatory type guard filter function is used to filter the elements of iterable and to apply the toGenerated function as well as the optional prefix and suffix functions to the accepted items with the more specific type U and their original indices.

      Note: empty strings being returned by toGenerated are treated as ordinary string representations, while the result of undefined makes this function to ignore the corresponding item and no separator is appended, if configured.

      Example:

        expandToNode`
      ${ joinToNode([x, y], e => e.propertyOfX, { filter: (e): e is X => e.$type === 'X' }) }
      `

      Type Parameters

      • T
      • U

      Parameters

      • iterable: Iterable<T, any, any> | T[]

        an Array or Iterable providing the elements to be joined

      • toGenerated: (element: U, index: number, isLast: boolean) => Generated

        a callback converting each individual element to a string, a CompositeGeneratorNode, or to undefined if to be omitted, defaults to the identity for strings, generator nodes, and undefined, and to String otherwise.

      • options: JoinOptions<T, U> & {
            filter: (element: T, index: number, isLast: boolean) => element is U;
        }

        config object including the here required type guard filter function, as well as optional separator and prefix and/or suffix providers, and activating conditional line-break insertion. In contrast to Array.filter the dedicated filter function enables the provision of the original element indices to toGenerated and the aforementioned functions, if the list is to be filtered.

      Returns undefined | CompositeGeneratorNode

      the resulting CompositeGeneratorNode representing iterable's content