0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kotlinのList<T>.fastZip()ってなんぞ?(個人的な覚書)

Posted at

とりあえずの覚書です。

イメージ
import androidx.compose.ui.util.fastZip

~省略~

    val hogeHogeList = listOf("テスト", "TEST", "1要素多い")
    val hugaHugaList = listOf("です~!", "だお(・ω・)")
    hogeHogeList.fastZip(hugaHugaList) { hoge, huga ->
        println(hoge + huga)
    }

↓実行結果↓

テストです~!
TESTだお(・ω・)

う要素数が少ないhugaHugaListの長さに合わせるため、hogeHogeListの"1要素多い"の分は出ない

  • zipってのが、要素数が少ない方のListに要素数を合わせてくれるやつ
  • .mapだと1つの引数(「{ hoge, huga ->」←ココ)で1つのListの要素しか使えないが、.fastZipを使うと、ラムダ式で2つのListの要素を使うことができる

2025-02-20_00h34_03.png

参考サイト

ラムダ式の書式
ラムダ式の書式は以下のようになります。
{ 引数 -> 関数の本体や処理内容 }

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?