1. Left Arrow Operator -> : generator
A generator can be used to generate individual values from a range
Example:
for (var x <- 1 to 10)
{
Code here
}
2. Right Arrow Operator:
=>
This operator converts the value on the left to a value on the right.
3. print and println
Scala build-in method print will print exactly the argument(string) given, multiple calling of print will not display string in a new line.
4. method and function
Functions are independent. Method have to be attached to a object/class/etc by definition.
Scala: abc = abc.map(f)
Python: abc = map(abc, f)
5. scala "eq" and python "is"
Both two keywords can be used to compare the identity of an object, eq, if the objects referred to by the two identifier (variable name) has the same memory address or not
The "==" operator compares the values of object referred by the identifier (variable name), eq, a = 1, b = 1, thus a == b return true
6. Intellij IDEA Java / Scala: IDE Error == > Output Path XXXXX / Cann't find class main XXXX
Two Sections in IDE that needs Attention !
Run/Debug Configuration
Project Structure
No.1: Make Sure main class and use classpath of module is properly configured
No.2: Make Sure project and module compiler output is properly configured
7. A function/method definition may not contain "=" if the function returns no value (unit type)
8. A float type literal must attach a "f" or "F" character at the end of the string to be treated as a float, otherwise it will be regarded as double type
9. The parameter definition of a function/method contains no val or var declaration keyword
10. Unlike python, class field reference within a class does not need to use the "self.xxx" convention
11. The i variable in a for loop need not to be declared (val, or var keyword)
12. Operations on a val mutable collection is allowed in scala. A val qualifier only restrict the reassignment of the identifier to other object, when applying to a non-collection object, this prevents the change of value because a change of value is equivalent to the change of reference. When the val qualifier is applying to a collection object, the validity of a change on the collection members is determined by the mutability of the collection.
13. Procedure v.s. method/function
Procedure = A function with result type Unit
14. Scala mkString v.s. toString
toString returns the string representation of the object, mkString returns the string contains as value in the object
15. An iterator is an object that has generation method that can be called to return each value per call.
A generator is an expression or operator that can be applied on an iterator. (Scala)
OR A generator is a function that act like an iterator
16. Json Object
A dictionary/Map is an object that the values in each of its name:value pair is primitive values (true, false, null, numbers or string) and/or object (Other dict or list). (Names can only be primitive values)
A list/Array is an object that contains primitive values and/or object (Other dict or list).
17. Compound types are not allowed as type tests in pattern matching (No generic type tests). The type erasure of such a compound type is simply T1.
val m1: Map[String, Int] = m collect {case (k:String, v:Int) => k->v}
instead of
val m1: Map[String, Int] = m collect {case e:(String, Int) => e}
http://lampwww.epfl.ch/~emir/bqbase/2006/10/16/erasure.html