Skip to content

Commit cd65214

Browse files
author
Singularity Indonesia
authored
Update README.md
1 parent 0216a0b commit cd65214

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff 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
143181
If you have some cool idea that I could put in it, please tell me, I would love to.
144182

0 commit comments

Comments
 (0)