Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/kotlin/Word.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ class Word(val parts: Sequence<String>) {
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)

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/WordTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down