Tuesday, February 18, 2014

Dictionary

  • Type parameters- Types in scala can be parametrized. That means you can add additional information that goes with main type.
    List[Double](1,2,3) //List(1.0, 2.0, 3.0) (result)
    List[String]("A","B","C") //List(A, B, C) (result)
    This information is not available at runtime. Instead are types are replaced with "Any" type
  • Pure function - does not have any side effects.
    - rest of code can affect processing only by giving input - functions can affect rest of code only by result
  • Traversable- Base type for all Scala collections
    - contains foreach method
    - might be strict (List) or non-strict (Stream)
    - might be ordered (Seq) or non-ordered (Set)
  • strict collection- all elements are computed when collection is computed.
  • non-strict collection- (lazy collection) - computation of elements may be deferred.
  • persistent collection
    - immutable
    - operations on collection return new updated structure
    - updated structure reffers to original and contains only differences
    - memory efficient
  • val items1 = List(1,2,3)
    val items2 = items1.updated(1, "A")
    
    - there's no way to modify original collection (items1)
    - though update method returns new collection (items2)
    - new collection contain only changes and reference to original
    - old items are shared by both collections
  • immutable- once created object does not change
  • REPL- (Run-Eval-Print Loop) - shell for Scala.
    Simple programming enviroment where user enters expressions, next they are evaluated, results are printed and process is repeated.
    scala
    Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_25).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> println("Hello world")
    Hello world
    
    scala> exit
    
  • No comments:

    Post a Comment