Scala Tutorialsを読む 21 Match as a Switch
http://scalatutorials.com/tour/interactive_tour_of_scala_match_as_a_switch.html
21 Match as a Switch
switchとしてのmatchか。as a でとしてって意味があるらしい。
Pattern matching will be familiar to anyone coming from a Haskell background,
パターンマッチはハスケルを背景にしている人には良く知られているであろう、
however it might look a bit weird at first for anyone coming from imperative languages.
命令型言語からの人にはパターンマッチは少し奇妙に見えるかもしれません。weirdは奇妙かJOJO's weird adventureなのかな。BIZARREか。
Pattern matching in it's most basic form, can look like an extended switch, with some differences:
最も基本的なパターンマッチは、switchを継承していると見る事ができますが、いくつかの違いがあります:
- The
match
keyword comes after the variable (selection match
compared toswitch(selection)
match
キーワードは値の後ろに来ます(selection match
はswitch(selection)
と同等- There is no need for
break;
break;
は必要ありません。- There is no fall through
- フォールスルーしません。
- default case is
case _
(orcase x
where x can be any lower case identifier, more about it in the next slides) - defaultのケースは
case _
です。(もしくはcase x
のxはすべての小文字識別子が書け、次のスライドで詳しく説明します)
Pattern matching can be very powerful beyond a switch
replacement, and will be explained in later slides
パターンマッチはswitch
を置き換えるに留まらずとても強力な事が出来きるので、更なる説明を以降のスライドでします。
See Also opens in new page
新しいページを開いて参照
- More on pattern matching
- パターンマッチの詳細