Dsl

data class Dsl<A>(val dsl: suspend ResourceScope.() -> A) : Resource<A>

Deprecated

Dsl is redundant and will be removed in Arrow 2.x.x in favor of the DSL. In case you think this method should stay, please provide feedback and your use-case on https://github.com/arrow-kt/arrow/issues

Replace with

import arrow.fx.coroutines.resource
resource { dsl() }

Constructors

Link copied to clipboard
fun <A> Dsl(dsl: suspend ResourceScope.() -> A)

Functions

Link copied to clipboard
@DelicateCoroutinesApi
suspend fun allocate(): Pair<A, suspend (ExitCase) -> Unit>

Deconstruct Resource into an A and a release handler. The release action must always be called, if never called, then the resource A will leak. The release step is already made NonCancellable to guarantee correct invocation like Resource or bracketCase, and it will automatically rethrow, and compose, the exceptions as needed.

Link copied to clipboard
@DelicateCoroutinesApi
suspend fun allocated(): Pair<suspend () -> A, suspend (A, ExitCase) -> Unit>
Link copied to clipboard
fun <B> ap(ff: Resource<(A) -> B>): Resource<B>
Link copied to clipboard
fun <B> flatMap(f: (A) -> Resource<B>): Resource<B>

Create a resource value of B from a resource A by mapping f.

Link copied to clipboard
fun <B> map(f: suspend (A) -> B): Resource<B>
Link copied to clipboard
fun <B, C> parZip(fb: Resource<B>, f: suspend (A, B) -> C): Resource<C>

fun <B, C> parZip(ctx: CoroutineContext = Dispatchers.Default, fb: Resource<B>, f: suspend (A, B) -> C): Resource<C>

Composes two Resources together by zipping them in parallel, by running both their acquire handlers in parallel, and both release handlers in parallel.

Link copied to clipboard
fun tap(f: suspend (A) -> Unit): Resource<A>

Useful for setting up/configuring an acquired resource

Link copied to clipboard
infix suspend tailrec fun <B> use(f: suspend (A) -> B): B

Use the created resource When done will run all finalizers

Link copied to clipboard
fun <B> zip(other: Resource<B>): Resource<Pair<A, B>>
inline fun <B, C> zip(other: Resource<B>, crossinline combine: (A, B) -> C): Resource<C>
inline fun <B, C, D, E> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, crossinline map: (A, B, C, D) -> E): Resource<E>
inline fun <B, C, D, E, G> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, crossinline map: (A, B, C, D, E) -> G): Resource<G>
inline fun <B, C, D, E, F, G, H> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, f: Resource<F>, crossinline map: (A, B, C, D, E, F) -> G): Resource<G>
inline fun <B, C, D, E, F, G, H> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, f: Resource<F>, g: Resource<G>, crossinline map: (A, B, C, D, E, F, G) -> H): Resource<H>
inline fun <B, C, D, E, F, G, H, I> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, f: Resource<F>, g: Resource<G>, h: Resource<H>, crossinline map: (A, B, C, D, E, F, G, H) -> I): Resource<I>
inline fun <B, C, D, E, F, G, H, I, J> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, f: Resource<F>, g: Resource<G>, h: Resource<H>, i: Resource<I>, crossinline map: (A, B, C, D, E, F, G, H, I) -> J): Resource<J>
inline fun <B, C, D, E, F, G, H, I, J, K> zip(b: Resource<B>, c: Resource<C>, d: Resource<D>, e: Resource<E>, f: Resource<F>, g: Resource<G>, h: Resource<H>, i: Resource<I>, j: Resource<J>, crossinline map: (A, B, C, D, E, F, G, H, I, J) -> K): Resource<K>

inline fun <B, C, D> zip(b: Resource<B>, c: Resource<C>, crossinline map: (A, B, C) -> D): Resource<D>

Combines two independent resource values with the provided map function, returning the resulting immutable Resource value. The finalizers run in order of left to right by using flatMap under the hood, but zip provides a nicer syntax for combining values that don't depend on each-other.

Properties

Link copied to clipboard
val dsl: suspend ResourceScope.() -> A

Extensions

Link copied to clipboard
fun <A> Resource<A>.asFlow(): Flow<A>

Runs Resource.use and emits A of the resource

Link copied to clipboard
infix fun <A> Resource<A>.release(release: suspend (A) -> Unit): Resource<A>

Composes a release action to a Resource.use action creating a Resource.

Link copied to clipboard
infix fun <A> Resource<A>.releaseCase(release: suspend (A, ExitCase) -> Unit): Resource<A>

Composes a releaseCase action to a Resource.use action creating a Resource.