All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.arrow.core.raise.Mappers.kt Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
@file:JvmMultifileClass
@file:JvmName("RaiseKt")
package arrow.core.raise

import arrow.core.Either
import arrow.core.Ior
import arrow.core.Option
import arrow.core.Some
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/** Run the [Effect] by returning [Either.Right] of [A], or [Either.Left] of [Error]. */
public suspend fun  Effect.toEither(): Either = either { invoke() }
/** Run the [EagerEffect] by returning [Either.Right] of [A], or [Either.Left] of [Error]. */
public fun  EagerEffect.toEither(): Either = either { invoke() }

/** Run the [Effect] by returning [Ior.Right] of [A], or [Ior.Left] of [Error]. */
public suspend fun  Effect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) }
/** Run the [EagerEffect] by returning [Ior.Right] of [A], or [Ior.Left] of [Error]. */
public fun  EagerEffect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) }

/** Run the [Effect] by returning [A], or `null` if raised with [Error]. */
public suspend fun  Effect.getOrNull(): A? = getOrElse { null }

/** Run the [EagerEffect] by returning [A], or `null` if raised with [Error]. */
public fun  EagerEffect.getOrNull(): A? = getOrElse { null }

/** Run the [Effect] by returning [Option] of [A], [recover] run the fallback lambda and returning its result of [Option] of [A]. */
public suspend fun  Effect.toOption(recover: suspend (error: Error) -> Option): Option = fold(recover) { Some(it) }
/** Run the [EagerEffect] by returning [Option] of [A], [recover] run the fallback lambda and returning its result of [Option] of [A]. */
public inline fun  EagerEffect.toOption(recover: (error: Error) -> Option): Option = fold(recover) { Some(it) }

/** Run the [Effect] by returning [Result] of [A], [recover] run the fallback lambda and returning its result of [Result] of [A]. */
public suspend fun  Effect.toResult(recover: suspend (error: Error) -> Result): Result =
  fold({ Result.failure(it)  }, { recover(it) }, { Result.success(it) })
/** Run the [EagerEffect] by returning [Result] of [A], [recover] run the fallback lambda and returning its result of [Result] of [A]. */
public inline fun  EagerEffect.toResult(recover: (error: Error) -> Result): Result =
  fold({ Result.failure(it)  }, { recover(it) }, { Result.success(it) })

/** Run the [Effect] by returning [Result] of [A], or [Result.Failure] if raised with [Throwable]. */
public suspend fun  Effect.toResult(): Result = result { invoke() }
/** Run the [EagerEffect] by returning [Result] of [A], or [Result.Failure] if raised with [Throwable]. */
public fun  EagerEffect.toResult(): Result = result { invoke() }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy