File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ class Word(val parts: Sequence<String>) {
2323 */
2424 fun toNotation (notation : StringNotation ) = notation.print (this )
2525
26+ /* *
27+ * Creates a new word, with all its parts transformed by the provided [transform] function.
28+ */
29+ fun mapParts (transform : (String ) -> String ) = Word (parts.map(transform))
30+
2631 /* *
2732 * Appends a part to this word.
2833 */
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ class WordTest {
2323
2424 @Test
2525 fun `allows to add parts` () {
26- expect((Word (" with" ) + " more" + " parts" )).feature(Word ::partsList).containsExactly(" with" , " more" , " parts" )
26+ expect((Word (" with" ) + " more" + " parts" ))
27+ .feature(Word ::partsList)
28+ .containsExactly(" with" , " more" , " parts" )
29+ }
30+
31+ @Test
32+ fun `allows to add words` () {
33+ expect(Word (" with" ) + Word (" more" , " parts" ))
34+ .feature(Word ::partsList)
35+ .containsExactly(" with" , " more" , " parts" )
36+ }
37+
38+ @Test
39+ fun `allows to transform parts` () {
40+ expect(Word (" a" , " b" , " c" ))
41+ .feature(Word ::mapParts, String ::toUpperCase)
42+ .feature(Word ::partsList)
43+ .containsExactly(" A" , " B" , " C" );
2744 }
2845}
You can’t perform that action at this time.
0 commit comments