Skip to content

Commit b1e2cb4

Browse files
authored
Merge pull request #34 from jGleitz/word-plus-varargs
feat: Word#plus(vararg String)
2 parents d3d6335 + 308d968 commit b1e2cb4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/kotlin/Word.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ class Word(val parts: Sequence<String>) {
4040
fun partsFromNotation(notation: StringNotation) = Word(parts.flatMap { it.fromNotation(notation).parts })
4141

4242
/**
43-
* Appends a part to this word.
43+
* Creates a copy of this word with the provided [part] appended.
4444
*/
4545
operator fun plus(part: String) = Word(parts + part)
4646

4747
/**
48-
* Appends all parts of the given [word] to this word.
48+
* Creates a copy of this word with all provided [parts] appended.
49+
*/
50+
fun plus(vararg parts: String) = Word(this.parts + parts)
51+
52+
/**
53+
* Creates a copy of this word with all parts of the provided [word] appended.
4954
*/
5055
operator fun plus(word: Word) = Word(parts + word.parts)
5156

src/test/kotlin/WordTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class WordTest {
4242
fun `allows to add parts`() {
4343
expect((Word("with") + "more" + "parts"))
4444
.toBe(Word("with", "more", "parts"))
45+
expect(Word("with").plus("more", "parts"))
46+
.toBe(Word("with", "more", "parts"))
4547
}
4648

4749
@Test

0 commit comments

Comments
 (0)