Hyperlinkv0.8.0-beta.28

Array

Array.zipconsteffect/Array.ts:2208
<B>(that: NonEmptyReadonlyArray<B>): <A>(
  self: NonEmptyReadonlyArray<A>
) => NonEmptyArray<[A, B]>
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>
<A, B>(
  self: NonEmptyReadonlyArray<A>,
  that: NonEmptyReadonlyArray<B>
): NonEmptyArray<[A, B]>
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>

Pairs elements from two iterables by position. If the iterables differ in length, the extra elements from the longer one are discarded.

When to use

Use when you need simple pairs of corresponding elements from two iterables.

Details

Returns NonEmptyArray when both inputs are non-empty.

Example (Zipping two arrays)

import { Array } from "effect"

console.log(Array.zip([1, 2, 3], ["a", "b"])) // [[1, "a"], [2, "b"]]
Source effect/Array.ts:22089 lines
export const zip: {
  <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>
  <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>
  <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>
  <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>
} = dual(
  2,
  <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)
)