LoginSignup
0
0

More than 5 years have passed since last update.

Option の中身を検証する、ちょっとカッコイイ?書き方

Posted at

本当にちょっとしたことだけど、Option の中身が期待通りかを確認するののスッキリした書き方をメモ。
exists までは思いつくけど、 Optioncontains があるのは、最初はピンとこなかった。

val op: Option[Int] = ???
op.map(_ == 334).getOrElse(false) // △
op.exists(_ == 334) // ○
op.contains(334) // ◎
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