arrow-core-data / arrow.core / kotlin.collections.Map / zip

zip

fun <K, A, B> Map<K, A>.zip(other: Map<K, B>): Map<K, Pair<A, B>>

Combines to structures by taking the intersection of their shapes and using Pair to hold the elements.

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
   mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3"))
  //sampleEnd
  println(result)
}

inline fun <Key, A, B, C> Map<Key, A>.zip(other: Map<Key, B>, map: (Key, A, B) -> C): Map<Key, C>

Combines to structures by taking the intersection of their shapes and combining the elements with the given function.

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
   mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) {
     key, a, b -> "$key -> $a # $b"
   }
  //sampleEnd
  println(result)
}

inline fun <Key, B, C, D, E> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, map: (Key, B, C, D) -> E): Map<Key, E> inline fun <Key, B, C, D, E, F> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, map: (Key, B, C, D, E) -> F): Map<Key, F> inline fun <Key, B, C, D, E, F, G> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, map: (Key, B, C, D, E, F) -> G): Map<Key, G> inline fun <Key, B, C, D, E, F, G, H> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, g: Map<Key, G>, map: (Key, B, C, D, E, F, G) -> H): Map<Key, H> inline fun <Key, B, C, D, E, F, G, H, I> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, g: Map<Key, G>, h: Map<Key, H>, map: (Key, B, C, D, E, F, G, H) -> I): Map<Key, I> inline fun <Key, B, C, D, E, F, G, H, I, J> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, g: Map<Key, G>, h: Map<Key, H>, i: Map<Key, I>, map: (Key, B, C, D, E, F, G, H, I) -> J): Map<Key, J> inline fun <Key, B, C, D, E, F, G, H, I, J, K> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, g: Map<Key, G>, h: Map<Key, H>, i: Map<Key, I>, j: Map<Key, J>, map: (Key, B, C, D, E, F, G, H, I, J) -> K): Map<Key, K> inline fun <Key, B, C, D, E, F, G, H, I, J, K, L> Map<Key, B>.zip(c: Map<Key, C>, d: Map<Key, D>, e: Map<Key, E>, f: Map<Key, F>, g: Map<Key, G>, h: Map<Key, H>, i: Map<Key, I>, j: Map<Key, J>, k: Map<Key, K>, map: (Key, B, C, D, E, F, G, H, I, J, K) -> L): Map<Key, L>

Do you like Arrow?

Arrow Org
<