Skip to content

Add Composer Function

Latest

Choose a tag to compare

@SingularityIndonesia SingularityIndonesia released this 10 Sep 15:36
· 4 commits to main since this release
cd65214

Compose Function Like Butter

fun f(x: Double): Double {
    // Define the implementation of f
    return x + 1
}

fun g(x: Double): Double {
    // Define the implementation of g
    return x * 2
}

fun h(x: Double): Double {
    // Define the implementation of h
    return x - 3
}

@Test
fun testComposition() {
    val x = 10.0 // Replace with your desired input value

    // Compose the functions and apply them to x
    val result = ::f o ::g o ::h o x

    // result ((10 - 3) * 2) + 1
    assertEquals(15.0, result)
}