LoginSignup
3
0

More than 5 years have passed since last update.

Rubyばかりやってたら一瞬戸惑ったmap() ≠ collect()

Posted at

Rustのチュートリアルを読んでいて一瞬理解できなくなるところがあったからメモ。

Rubyばかり使っていたらこの部分で戸惑った。
食事する哲学者より


    let handles: Vec<_> = philosophers.into_iter().map(|p| {
        thread::spawn(move || {
            p.eat();
        })
    }).collect();

Rubyではmap()とcollect()は名前が違うだけで同じメソッドなので、なんで同じメソッドを繰り返しているのか、と首をかしげた。

ちょっと調べたらわかった。map()はMap型を返すので、collect::()をして型変換をする必要があるらしい。

へーって思った。まる。

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