arrow-fx / arrow.fx / IO / ap

ap

fun <B> ap(ff: IOOf<(A) -> B>): IO<B>

Given both the value and the function are within IO, apply the function to the value.

import arrow.fx.IO

fun main() {
  //sampleStart
  val someF: IO<(Int) -> Long> = IO.just { i: Int -> i.toLong() + 1 }
  val a = IO.just(3).ap(someF)
  val b = IO.raiseError<Int>(RuntimeException("Boom")).ap(someF)
  val c = IO.just(3).ap(IO.raiseError<(Int) -> Long>(RuntimeException("Boom")))
  //sampleEnd
  println("a: $a, b: $b, c: $c")
}

Do you like Arrow?

Arrow Org
<