arrow-fx / arrow.fx.extensions.io.async / arrow.Kind / effectMap

effectMap

@JvmName("effectMap") fun <A, B> Kind<ForIO, A>.~~effectMap~~(f: suspend (A) -> B): IO<B> Deprecated: The IO datatype and it’s related type classes will disappear in Arrow 0.13.0. All useful operations are offered directly over suspend functions by Arrow Fx Coroutines. https://arrow-kt.io/docs/fx/async/

Helper function that provides an easy way to construct a suspend effect

 import arrow.fx.*
import arrow.fx.extensions.io.async.*
import arrow.core.*


 import kotlinx.coroutines.Dispatchers

 fun main(args: Array<String>) {
  //sampleStart
  suspend fun logAndIncrease(s: String): Int {
     println(s)
     return s.toInt() + 1
  }

  val result = IO.async().effect(Dispatchers.Default) { Thread.currentThread().name }.effectMap { s: String -> logAndIncrease(s) }
  //sampleEnd
  println(result)
 }

Do you like Arrow?

Arrow Org
<