tag:blogger.com,1999:blog-7317245822288637185.post6251968943750042044..comments2023-03-28T10:19:42.467-07:00Comments on Graham Hacking Scala: How to match for the last item in a List in ScalaGraham Leahttp://www.blogger.com/profile/07862939329898536954noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7317245822288637185.post-19069087673918662262011-01-13T04:29:34.974-08:002011-01-13T04:29:34.974-08:00Thanks for that, Margus!
I've had a lot more p...Thanks for that, Margus!<br />I've had a lot more practice with using and writing extractors since this post, so lately I think I have been doing what you suggested.<br />It's funny sometimes to look back on how you did things when you were first learning.<br />Cheers,<br />Graham.Grazerhttps://www.blogger.com/profile/00435359638152521056noreply@blogger.comtag:blogger.com,1999:blog-7317245822288637185.post-14975515731430687262011-01-13T02:55:40.925-08:002011-01-13T02:55:40.925-08:00FYI, you don't have to use :: operator for mat...FYI, you don't have to use :: operator for matching lists. This also works:<br /><br />list match {<br />case Nil => "Nope: it's empty"<br />case List(one) => "Yep: just one"<br />case List(one, two) => "Nope: there's exactly two"<br />case _ => "Nope: there's at least three"<br />}<br /><br />In my opinion, this makes it more clear that you are actually looking for list of one or two elements.Margushttps://www.blogger.com/profile/03952175705505173721noreply@blogger.com