0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

zipメソッドに3つの引数を渡したいときの実装メモ

Posted at

概要

zipメソッドに3つの引数を渡したいときどのように実装するか

実装

let array1 = [1, 2, 3]
let array2 = ["a", "b", "c"]
let array3 = [true, false, true]

// zipを使って3つの配列を処理
for (element1, (element2, element3)) in zip(array1, zip(array2, array3)) {
    print("element1: \(element1), element2: \(element2), element3: \(element3)")
}

zipメソッドをネストして使用することで実現可能です。
zip(array2, array3)は、array2とarray3の要素をペアにします。これにより、(element2, element3)というタプルの配列を作ることができます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?