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).
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 }) }
`
an Array or Iterable providing the elements to be joined
OptionaltoGenerated: (element: T, index: number, isLast: boolean) => Generateda 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).
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' }) }
`
an Array or Iterable providing the elements to be joined
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.
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.
the resulting CompositeGeneratorNode representing iterable's content
Joins the elements of the given
iterableof 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, orundefinedand 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
iterableare treated as ordinary string representations, while the value ofundefinedmakes this function to ignore the corresponding item and no separator is appended, if configured.Examples: