Skip to content

Commit

Permalink
Merge pull request #34 from jGleitz/word-plus-varargs
Browse files Browse the repository at this point in the history
feat: Word#plus(vararg String)
  • Loading branch information
jGleitz authored Feb 18, 2020
2 parents d3d6335 + 308d968 commit b1e2cb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit b1e2cb4

Please sign in to comment.