Skip to content
Mario Arias edited this page Sep 17, 2015 · 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