Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Created August 17, 2012 20:06
Show Gist options
  • Save matthandlersux/3382144 to your computer and use it in GitHub Desktop.
Save matthandlersux/3382144 to your computer and use it in GitHub Desktop.

Revisions

  1. matthandlersux created this gist Aug 17, 2012.
    30 changes: 30 additions & 0 deletions whywrong.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    class Test {
    def pullOutType[V](f:Map[String, V] => Unit) {
    var map = Map[String, V]()
    val params = Map("string" -> "string", "int" -> 20, "list" -> List("ok", "then"))

    params.foreach {
    case (field, value) => value match {
    case v:V => map = map + (field -> v)
    case _ => null
    }
    case _ => null
    }

    f(map)
    }
    }

    val x = new Test

    x.pullOutType[List[String]] { data:Map[String, List[String]] =>
    assert(data.size == 2)
    }

    x.pullOutType { data:Map[String, String] =>
    assert(data.first == "string")
    }

    x.pullOutType { data:Map[String, Int] =>
    assert(data.first == 20)
    }