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>) {
23
23
*/
24
24
fun toNotation (notation : StringNotation ) = notation.print (this )
25
25
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
+
26
31
/* *
27
32
* Appends a part to this word.
28
33
*/
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ class WordTest {
23
23
24
24
@Test
25
25
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" );
27
44
}
28
45
}
You can’t perform that action at this time.
0 commit comments