Match Expressions with Pattern Guards

Published on Author adminLeave a comment

Here is an example for match expression with Pattern Guard

object _04MatchExpression_PatternGuards {
   def main(args: Array[String]): Unit = {
      val url: String = "Jan";

     val monthType = url match {
            case url if url.endsWith(".org") => "Educational Websites";
            case url if url.endsWith(".com") => "Commercial Websites";
            case url if url.endsWith("") => "Indian Websites"
            case _=> "Unknown Input";

Leave a Reply

Your email address will not be published. Required fields are marked *