concat method

  1. @override
PromptValue concat(
  1. PromptValue other
)
override

Merges this prompt value with another by concatenating the content.

Implementation

@override
PromptValue concat(final PromptValue other) => switch (other) {
  final StringPromptValue other => ChatPromptValue([
    ...messages,
    ChatMessage.humanText(other.value),
  ]),
  final ChatPromptValue other => ChatPromptValue(
    List.generate(
          max(messages.length, other.messages.length),
          (index) => (
            index < messages.length ? messages[index] : null,
            index < other.messages.length ? other.messages[index] : null,
          ),
        )
        .map((final pair) {
          final (message, otherMessage) = pair;
          if (message == null) {
            return otherMessage;
          } else if (otherMessage == null) {
            return message;
          } else {
            return message.concat(otherMessage);
          }
        })
        .nonNulls
        .toList(growable: false),
  ),
};