Skip to content
Brandon Ibbotson edited this page Jan 29, 2018 · 4 revisions

funKTionale includes an implementation of Identity Function

import org.funktionale.utils.*

private val add5 = {(i: Int) -> i + 5 }
private val multiplyBy2 = {(i: Int)-> i * 2 }

private fun applyTwoFunctions(i: Int, firstFunction: (Int) -> Int, secondFunction: (Int) -> Int): Int {
  val x = firstFunction(i)
  return secondFunction(x)
}

@Test fun testIdentity() {

  assertEquals(applyTwoFunctions(2, add5, multiplyBy2), 14)

  assertEquals(applyTwoFunctions(2, add5, identity()), 7) // Same as apply only the first function

  assertEquals(applyTwoFunctions(2, identity(), identity()), 2) // No modifications
}
Clone this wiki locally