Function

Scala: Seq, Map and Set as functions

Yesterday my mate asked me: “I have a List[String] and a Map[String, Int] and I want a List[Int] where its values are those of the Map whose keys match the List[String] elements, maintaining the order. Should I use pattern matching?”. I know, the sentence is a bit convoluted but the code will make it clear, hopefully. Anyway, I replied: “No, you don’t need pattern matching, you just need this”: scala> val m = Map("a" -> 1, "b" -> 2, "c" -> 3) m: scala.

The Function class in JavaScript

Most programmers know how to define and use a function in JavaScript. For example the following function displays an alert containing the string passed in as a parameter: function displayAlert(sText) { alert(sText); } // Then you call it this way displayAlert("Hello World!"); How many developers, however, know that JavaScript functions are actually objects? Indeed, you can define the previous function using the Function class: var displayAlert = new Function("sText", "alert(sText);"); //.