From 308d968ada2fe10e55fecee3c0b9b3990052c261 Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Tue, 18 Feb 2020 19:47:16 +0200 Subject: [PATCH] feat: Word#plus(vararg String) --- src/main/kotlin/Word.kt | 9 +++++++-- src/test/kotlin/WordTest.kt | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/Word.kt b/src/main/kotlin/Word.kt index a0942df..c8f9b63 100644 --- a/src/main/kotlin/Word.kt +++ b/src/main/kotlin/Word.kt @@ -40,12 +40,17 @@ class Word(val parts: Sequence) { fun partsFromNotation(notation: StringNotation) = Word(parts.flatMap { it.fromNotation(notation).parts }) /** - * Appends a part to this word. + * Creates a copy of this word with the provided [part] appended. */ operator fun plus(part: String) = Word(parts + part) /** - * Appends all parts of the given [word] to this word. + * Creates a copy of this word with all provided [parts] appended. + */ + fun plus(vararg parts: String) = Word(this.parts + parts) + + /** + * Creates a copy of this word with all parts of the provided [word] appended. */ operator fun plus(word: Word) = Word(parts + word.parts) diff --git a/src/test/kotlin/WordTest.kt b/src/test/kotlin/WordTest.kt index 670e85d..4405daa 100644 --- a/src/test/kotlin/WordTest.kt +++ b/src/test/kotlin/WordTest.kt @@ -42,6 +42,8 @@ class WordTest { fun `allows to add parts`() { expect((Word("with") + "more" + "parts")) .toBe(Word("with", "more", "parts")) + expect(Word("with").plus("more", "parts")) + .toBe(Word("with", "more", "parts")) } @Test