zip

inline fun <B, C> zip(other: Resource<B>, crossinline combine: (A, B) -> C): Resource<C>

Deprecated

zip 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 { combine(this.bind(), other.bind()) }

fun <B> zip(other: Resource<B>): Resource<Pair<A, B>>

Deprecated

zip 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 { Pair(this.bind(), other.bind()) }

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

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind()) }

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.

Useful to compose up to 9 independent resources, see example for more details on how to use in code.

import arrow.fx.coroutines.*

class UserProcessor {
fun start(): Unit = println("Creating UserProcessor")
fun shutdown(): Unit = println("Shutting down UserProcessor")
fun process(ds: DataSource): List<String> =
ds.users().map { "Processed $it" }
}

class DataSource {
fun connect(): Unit = println("Connecting dataSource")
fun users(): List<String> = listOf("User-1", "User-2", "User-3")
fun close(): Unit = println("Closed dataSource")
}

class Service(val db: DataSource, val userProcessor: UserProcessor) {
suspend fun processData(): List<String> = userProcessor.process(db)
}

val userProcessor = resource {
UserProcessor().also(UserProcessor::start)
} release UserProcessor::shutdown

val dataSource = resource {
DataSource().also { it.connect() }
} release DataSource::close

suspend fun main(): Unit {
userProcessor.zip(dataSource) { userProcessor, ds ->
Service(ds, userProcessor)
}.use { service -> service.processData() }
}

See also

if you want to combine independent resources in parallel

to combine resources that rely on each-other.


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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind()) }

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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind(), e.bind()) }

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>

Deprecated

This method will be removed in Arrow 2.x.x in favor of the DSL

Replace with

import arrow.fx.coroutines.resource
zip 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

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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) }

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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) }

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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) }

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>

Deprecated

zip 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 { map(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) }