File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,44 @@ val d = a[10] // result = None
139139
140140</details >
141141
142+ ### 5. Composer
143+
144+ Compose functions like butter.
145+
146+ <details >
147+ <summary >Click to see more</summary >
148+ I introduce you the composer infix `` o `` . You can use pure math composition style to compose your functions.
149+
150+ ``` kotlin
151+ fun f (x : Double ): Double {
152+ // Define the implementation of f
153+ return x + 1
154+ }
155+
156+ fun g (x : Double ): Double {
157+ // Define the implementation of g
158+ return x * 2
159+ }
160+
161+ fun h (x : Double ): Double {
162+ // Define the implementation of h
163+ return x - 3
164+ }
165+
166+ @Test
167+ fun testComposition () {
168+ val x = 10.0
169+
170+ // Compose the functions and apply them to x
171+ val result = ::f o ::g o ::h o x
172+
173+ // result ((10 - 3) * 2) + 1
174+ assertEquals(15.0 , result)
175+ }
176+ ```
177+
178+ </details >
179+
142180# Many More Coming
143181If you have some cool idea that I could put in it, please tell me, I would love to.
144182
You can’t perform that action at this time.
0 commit comments