progs/app3.scala
changeset 98 3d585e603927
parent 93 82ac034dcc9d
--- a/progs/app3.scala	Mon Sep 23 17:39:31 2013 +0100
+++ b/progs/app3.scala	Mon Sep 23 22:23:55 2013 +0100
@@ -6,16 +6,15 @@
     hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString
   }
 
-  def gt_cookie(c: Option[Cookie]) : Int = 
-    c.map(_.value.split("/")) match {
-      case Some(Array(s, h)) 
-        if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt 
-      case _ => 0
-    }
+  def gt_cookie(c: Cookie) : Int = c.value.split("/") match {
+    case Array(s, h) 
+      if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt 
+    case _ => 0
+  }
 
   def mk_cookie(i: Int) : Cookie = {
-    val s = i.toString
-    Cookie("visits", s + "/" + mk_hash(s))
+    val hash = mk_hash(i.toString)
+    Cookie("visits", s"$i/$hash")
   }
    
   def index = Action { request => ... }